2015-06-07 40 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();