Topic-icon Restrict geo lookup using google API

  • davidmarshall15
  • davidmarshall15's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
14 Jul 2018 14:22 #41965 by davidmarshall15
Restrict geo lookup using google API was created by davidmarshall15
Hi,

I don't have a key and it seems google is becoming more restrictive on the number of updates.
To workaround this, I am having new members register with their city+country, this is enough for the sites purpose.

Then in geocoder I have set to only update if the coords are null but it is still making an API call.

For the next release can you update the geocodeUser function to this:
	function geocodeUser($user,$cbUser)
	{
		if(JFactory::getUser()->id != $cbUser->user_id){
			return;
		}
		
		$db 	= JFactory::getDbo();
		$params = $this->params;
		$mode 	= $params->get('mode',0);
		
		if ( ($mode==1 && ($cbUser->cb_geolat == '' || $cbUser->cb_geolng == ''))||$mode==0 )
		{ 
            $place 	= $this->geocodeAddress($params , $cbUser);
			$cbUser->cb_geolat = $place['latitude'] ? $place['latitude'] : $cbUser->cb_geolat;
			$cbUser->cb_geolng = $place['longitude'] ? $place['longitude'] : $cbUser->cb_geolng;			
			$q ="UPDATE #__comprofiler 
			SET cb_geolat='".$cbUser->cb_geolat."',cb_geolng='".$cbUser->cb_geolng."' 
			WHERE id='".$cbUser->user_id."'";
			$db->setQuery($q);
           	$db->execute();
		}
	}

All I have done is move the geocodeAddress call to inside the mode+empty coords check.

Thanks
David

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum
Disclaimer: Nordmograph is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.
Copyright © 2021 Nordmograph - Joomla extensions. All Rights Reserved.
Joomla! is Free Software released under the GNU General Public License.
Browser of the future