Search code examples
c#restgoogle-mapslatitude-longitude

How to find latitude and longitude using C#


I have a WCF service in C#.

In the Service call client sends a city name. I want to convert the city name to latitudes and longitudes and store in Database under demographics.

I am planning to use Google API to implement above functionality.

I have obtained an API key from Google and its of type 'Service account'.

How can I obtain the latitude and longitude using which APIs?

Do I need to install some SDK or any REST Service will do?


Solution

  • If you want to use the Google Maps API have a look at their REST API, you don't need to install a Google Maps API just send a Request like

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

    and you will get a response XML.

    For response JSON:

    https://maps.googleapis.com/maps/api/geocode/json?address=1600+Estância+Sergipe,&key=**YOUR_API_KEY**
    

    For more Information have a look at

    https://developers.google.com/maps/documentation/geocoding/index#GeocodingRequests