1

I am pretty new to the Google API. I have in my database some addresses information stored and I am calling it to my page with a PHP while loop. What I would like is that it shows the location of the address in Googlemaps based on street name and city stored in database.

The only way I see how to use Google maps is with latitude and longitude. Is there a way to convert the street name and city into these coordinates so it generate correct maps location on my website?

I hope someone can provide me with an answer. Thank you in advance.

Facyo Kouch
  • 787
  • 8
  • 26
  • 1
    Check [geocoding](https://developers.google.com/maps/documentation/javascript/geocoding). You can use an address to get location of it. – Anto Jurković Apr 23 '14 at 21:11
  • possible duplicate of [Google Maps API - Get Coordinates of address](http://stackoverflow.com/questions/3652951/google-maps-api-get-coordinates-of-address) – geocodezip Apr 23 '14 at 21:21

2 Answers2

2

I found a PHP solution that generates the lat and lng that works for me. Hopefully also for you.

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
$lat = $obj->results[0]->geometry->location->lat;
$lng = $obj->results[0]->geometry->location->lng;
echo $lat;

It generates a JSON with the address and with PHP you can get the lat and lng. Just add your address in the $url string after "address="

Facyo Kouch
  • 787
  • 8
  • 26
0

Use http://maps.google.com/maps?q= and add the adress string at the end of the url.

If you want to use it for mobile look at the question. Suppress chooser dialog when calling Google map using intent

Community
  • 1
  • 1
Maurice
  • 792
  • 11
  • 34