Skip to main content
 首页 » 编程设计

c#之如何在 Windows 8.1 App 中使用地理编码

2024年02月13日23开发

我需要从地址获取地理坐标。我试着走这条路: http://www.braincastexception.com/wp7-web-services-first-part-geocodeservice/但有一些错误。

1) 错误的论点:

GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); 

2) 事件不存在:

geocodeService.GeocodeCompleted += (sender, e) => geoCode_GeocodeCompleted(sender, e); 

本文涉及 Windows Phone 7,但我使用的是 Windows 8.1 应用程序。也许 Windows 8.1 App 有另一种解决方案?我该怎么办?

请您参考如下方法:

要进行地理编码,请执行以下操作:

async void GetLocation(string address, Geopoint queryHintPoint) 
{ 
    var result = await MapLocationFinder.FindLocationsAsync(address, queryHintPoint); 
 
    // Get the coordinates 
    if(result.Status == MapLocationFinderStatus.Success) 
    { 
        double lat = result.Locations[0].Point.Position.Latitude; 
        double lon = result.Locations[0].Point.Position.Longitude; 
    } 
} 

并反向地理编码:

async void GetLocationName(Geopoint yourLocation) 
{ 
    var result = await MapLocationFinder.FindLocationsAtAsync(yourLocation); 
 
    // Get the address 
    if(result.Status == MapLocationFinderStatus.Success) 
    { 
        string address = result.Locations[0].Address.StreetNumber + result.Locations[0].Address.Street; 
    } 
} 

查看这篇文章:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631249.aspx

它解释了如何在 Windows Phone 8.1 map 中获取位置。