2015-06-07 41 views
0

我想从地址获取纬度和经度。在windows phone 8.1中将地址转换为经度和纬度c#

Geolocator geo = new Geolocator(); 
try 
{ 
    Geoposition geoposition1 = await geo.GetGeopositionAsync(
     maximumAge: TimeSpan.FromMinutes(5), 
     timeout: TimeSpan.FromSeconds(10)); 

    //With this 2 lines of code, the app is able to write on a Text Label the Latitude and the Longitude, given by {{Icode|geoposition}} 
    //location1.Text = "GPS:" + geoposition.Coordinate.Latitude.ToString("0.00") + ", " + geoposition.Coordinate.Longitude.ToString("0.00"); 
} 
//If an error is catch 2 are the main causes: the first is that you forgot to include ID_CAP_LOCATION in your app manifest. 
//The second is that the user doesn't turned on the Location Services 
catch (Exception ex) 
{ 
    //exception 
} 
// find the address of the tapped location 
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(geopoint); 

// If successful then display the address. 
if (result.Status == MapLocationFinderStatus.Success) 
{ 
    if (result.Locations.Count > 0) 
    { 
     string display; 
     if (string.IsNullOrEmpty(result.Locations[0].Address.Street)) 
     { 
      display = result.Locations[0].Address.Town + ", " + 
      result.Locations[0].Address.Region; 
     } 
     else 
     { 
      display = result.Locations[0].Address.StreetNumber + " " + 
      result.Locations[0].Address.Street; 
     } 

     tbAddress.Text = display; 
     //tbAddress1.Text = display; 
    } 
    else 
    { 
     // string msg = this.resourceLoader.GetString("NoAddress"); 
     // tbAddress.Text = msg; 
    } 
} 

这是我目前已经实现了,现在我想存储在display的位置,另外两个文本块的显示。谢谢你的任何建议。

回答

0

我想补充的是这样的:

display += " Latitude: " + result.Locations[0].Point.Position.Latitude.ToString(); 
display += " Longitude: " + result.Locations[0].Point.Position.Longitude.ToString();