Get Longitude and Latitude from Country Name

user1777165 picture user1777165 · Oct 26, 2012 · Viewed 9.4k times · Source

I have Gmaps embedded in my site which pulls out a list of dealers from my database around the world and plots their location with a marker based on the dealer postcode in Gmaps. This works great however I need to extend this functionality to support dealers who do not have a postcode but rather, they are assigned to Countries.

So for example, Test Dealer could be assigned to Germany and Belgium so I need to somehow get a generic longitude and latitude value for the country names "Germany" and "Belgium" and then show a marker for those long/lat values.

Is this possible? If so, where do I start?!

Thanks for reading. kris

Answer

Kevin Antonio picture Kevin Antonio · Oct 29, 2012

Try using google's geocoder. Just provide a generic address, in your case a country and it will return the center point of that country together with the coordinates(latitude and longitude)

Here's a link. https://developers.google.com/maps/documentation/javascript/geocoding