Reputation: 489
how to find latitude and longitude of a address in Wp7
ex :
If I give the location name : "New York" then i want get its latitude and longitude.
thanks in advance
Upvotes: 0
Views: 429
Reputation: 1874
WebClient webClient = new WebClient();
string xml = webClient.DownloadString("http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=xml");
Upvotes: 2
Reputation: 1874
This should work:
Class for deserializing the json string
public class PlaceInfo
{
public string place_id { get; set; }
public string licence { get; set; }
public string osm_type { get; set; }
public string osm_id { get; set; }
public List<string> boundingbox { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string display_name { get; set; }
public string @class { get; set; }
public string type { get; set; }
public double importance { get; set; }
public string icon { get; set; }
}
This is the code to get the informations from the website: Format is JSON, i'm using the json serializor of c#
using System.Runtime.Serialization; using System.Runtime.Serialization.Json;
WebClient webClient = new WebClient();
string jsonString = webClient.DownloadString("http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=json");
//load into memorystream
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
{
//parse
var ser = new DataContractJsonSerializer(typeof(PlaceInfo[]));
PlaceInfo[] obj = (PlaceInfo[])ser.ReadObject(ms);
}
the array obj has now all places which where found with that name. for example jsut take the first place which was found obj[0].lon and obj[0].lat
Upvotes: 2
Reputation: 1874
maybe you can use openstreetmaps:
http://nominatim.openstreetmap.org/search?city=%22new%20york%22&format=json
http://nominatim.openstreetmap.org/search?city="---cityname---"&countrycodes="---CountryCode---"&limit=2&format=json
http://wiki.openstreetmap.org/wiki/Nominatim
you can get the result as json or xml
Upvotes: 1