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?

有帮助吗?

解决方案

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top