我正在使用以下服务参考来获取纬度和经度的位置详细信息
http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc
我将上述网址添加到我的服务引用类中,并尝试通过调用以下方法获取位置详细信息
public void reverse()
{
string Results = "";
try
{
// Set a Bing Maps key before making a request
string key = "Bing Maps Key";
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
// Set the credentials using a valid Bing Maps key
reverseGeocodeRequest.Credentials = new GeoCodeService.Credentials();
reverseGeocodeRequest.Credentials.ApplicationId = key;
// Set the point to use to find a matching address
GeoCodeService.Location point = new GeoCodeService.Location();
point.Latitude = 47.608;
point.Longitude = -122.337;
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient();
**GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);**
}
catch (Exception ex)
{
Results = "An exception occurred: " + ex.Message;
}
但是我收到以下错误消息
GeoCodeService.GeoCodeServiceClient不包含ReverseGeocode的定义,也没有扩展方法
找不到GeoCodeService.GeoCodeServiceClient。
帮助我解决问题。并告诉我这是查找位置详细信息的最佳方式。
答案 0 :(得分:1)
在Windows Phone 8中,您有内置的反向地理编码API,无需向Bing地图添加服务参考:
List<MapLocation> locations;
ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = new GeoCoordinate(47.608, -122.337);
query.QueryCompleted += (s, e) =>
{
if (e.Error == null && e.Result.Count > 0)
{
locations = e.Result as List<MapLocation>;
// Do whatever you want with returned locations.
// e.g. MapAddress address = locations[0].Information.Address;
}
};
query.QueryAsync();