Question

How can I get a latitude and longitude of some location in asp.net MVC4?

For example how can I get the latitude and longitude of Hafeez center, Lahore, Punjab, Pakistan?

Was it helpful?

Solution

You can use the google GeoCoding service to convert an address to a set of coordinates.

For example for your address you would call:

http://maps.googleapis.com/maps/api/geocode/xml?address=Hafeez+center,Lahore,Punjab,Pakistan&sensor=false

My recommendation would be to do something like:

var responseDocument = XDocument.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=Hafeez+center,Lahore,Punjab,Pakistan&sensor=false");

Then read the xml to the information you need.

Edited to add - make sure you check google's terms and conditions, they prohibit some types of applications!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top