0

How to convert a city/state to a geo location (lat/long) using bing?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

3 Answers3

3

This example uses Yahoo's API but gets the job done for me. Will work if you just submit a zipcode or city,state. I use a dataset because I'm addicted to them.

private void YahooParseLatLon(string address_)
{
HttpWebRequest feed =
HttpWebRequest.Create("http://local.yahooapis.com/MapsService/V1/geocode?
appid=YOUR_APID&street=" + address_) as HttpWebRequest;

WebResponse feedresponse = default(WebResponse);
feedresponse = feed.GetResponse();
DataSet data = new DataSet();
data.ReadXml(feedresponse.GetResponseStream());
if (!string.IsNullOrEmpty(data.Tables(0).Rows(0).Item("Address"))) {
//process lat lon values
string lat = data.Tables(0).Rows(0).Item("Latitude");
string lon = data.Tables(0).Rows(0).Item("Longitude");
}
else {
//process no address found
}
data.Dispose();
feedresponse = null;
feed = null;
}

I use this to collect lat/lon for addresses on new orders placed in my company's system. I then use this data to populate a map integrated into a scheduling application for our field agents.

CliffyB
  • 29
  • 3
0

Here is a complete tutorial on MSDN to do what you are looking for.

Note you want to make sure you are linking to 7.0 and NOT 6.3.

clamchoda
  • 4,411
  • 2
  • 36
  • 74
0

I've found a geotag generator use can use.

Anonymous
  • 9
  • 1