1

Possible Duplicate:
how i can get latitude , longitude of a location programmatically or using a api

I am using > http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXML.htm. to get the weather detials of location. Here I need to pass latitude and longitude to the webmethod. I have location name but not the latitude & longitude values.So I want to get these 2 values of a location. Is there any way to get it.

Community
  • 1
  • 1
karthik k
  • 3,751
  • 15
  • 54
  • 68
  • Could you give an example for a location name you're working with? – takrl Jun 06 '11 at 10:46
  • In that case, [this](http://stackoverflow.com/questions/3490622/get-latitude-and-longitude-based-on-location-name-google-maps-api) or [this](http://stackoverflow.com/questions/3246553/googles-geocode-convert-city-state-into-latitude-longitude) may be helpful. – takrl Jun 06 '11 at 11:04

1 Answers1

2

Since you tagged the question with Google I presume you would want to use the Google Geocoding API service? The documenation there pretty much explains how to use it - you pass the address as a query-string parameter to the service (via simple REST like URL) and you can get back either XML or JSON. An example of an XML query:

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

As part of the XML response you will see the lat/long:

<location>
  <lat>
     37.4213068
  </lat>
  <lng>
     -122.0852900
   </lng>
</location>

Just remember to set the sensor parameter to either true or false as this is required.

Note the v3 API doesn't require an API key but does have some usage limitations you should be aware of, including:

  • a query limit of 2,500 geolocation requests per day.
  • the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited
Dan Diplo
  • 25,076
  • 4
  • 67
  • 89