Jump to content

Google Maps API Querries


Recommended Posts

Hello!

I am trying to find a way to assign the JSON value Google Map's API Returns when passed an address.  I would search Google, but I am only a few month deep into PHP and really don't know what keywords to use.  I really don't even know what a JSON is? 

Anyway, I found this article that explains how to query Google Maps with an address and have it return a GPS Location.  When I tested it in my browser, the text appears.  I just don't know what to use to take what the browser is displaying and assign in to an Object in a PHP page.

This is the Google Maps Query:

http://maps.google.com/maps/geo?q="ADDRESS"&output=csv&oe=utf8

 

This my function where I want to use this:

//Querries Google Map's API with an address and assigns the returned GPS Location 
//to this Object
public function build_me($this_address)
{
	//Builds the query from the address array to send to the Goole Maps API
	$query = $this_address["Line1"].",".$this_address["Line2"].",".
		 $this_address["City"].",".$this_address["State"].",".$this_address["Zip"];

	//Location_Array = http://maps.google.com/maps/geo?q=$query&output=csv&oe=utf8
	$this->latitude  = //Location_Array['Something'];
	$this->longitude = //Location_Array['Something'];
}

 

This is the article that I am referring to:

http://martinsikora.com/how-to-get-gps-coordinates-from-an-address

 

My question is, how would I go about doing this?  Are there any good tutorials on this?

Thanks in advance for anyone pointing me in the right direction!

Link to comment
Share on other sites

Solved. 

Via @bažmegakapa from StackOverflow:

 

 

Actually the URL you are showing will produce a CSV output (that is why it has the output=csv parameter). You can see it if you simply insert it into your browser (Downing Street 10):

 

200,8,45.9797693,-66.5854067

 

Here are some useful resources to get the job done:

 

cURL to make the call to the Google API

cURL Tutorial

str_getcsv() to parse a CSV string into a PHP array

(json_decode() to translate JSON to PHP arrays/objects - just in case you're gonna need it later)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.