views:

23

answers:

1

Does anyone know how I can obtain latitude and longtitude from the Country Name using Google Maps API?

A: 

It seems to be possible to obtain a Latitude/Longitude pair that roughly points to the center of the country by sending the country name to the Geocoder. See e.g. the XML response to

http://maps.google.com/maps/geo?q=Spain&output=xml

The response is

 <kml xmlns="http://earth.google.com/kml/2.0"&gt;&lt;Response&gt; 
  <name>Spain</name> 
  <Status> 
    <code>200</code> 
    <request>geocode</request> 
  </Status> 
  <Placemark id="p1"> 
    <address>Spain</address> 
    <AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>ES</CountryNameCode><CountryName>Espanya</CountryName></Country></AddressDetails> 
    <ExtendedData> 
      <LatLonBox north="45.2440000" south="35.1730000" east="5.0980000" west="-12.5240000" /> 
    </ExtendedData> 
    <Point><coordinates>-3.7492200,40.4636670,0</coordinates></Point> 
  </Placemark> 
</Response></kml> 
Pekka