在BingMap中获取经度和纬度的位置名称

问题描述:

我是WP7开发人员。我有一个位置的经纬度。反正有信息获取坐标定义的位置,即经度和纬度。 谢谢!在BingMap中获取经度和纬度的位置名称

是的,你可以通过Bing Maps REST API来做到这一点,你需要执行reverse geocode。这是通过GET-ING以下请求:

http://dev.virtualearth.net/REST/v1/Locations/47.64054,-122.12934?o=xml&key=BingMapsKey 

将在XML格式返回地址:

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1"> 
    <Copyright> 
    Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation. 
    </Copyright> 
    <BrandLogoUri> 
    http://dev.virtualearth.net/Branding/logo_powered_by.png 
    </BrandLogoUri> 
    <StatusCode>200</StatusCode> 
    <StatusDescription>OK</StatusDescription> 
    <AuthenticationResultCode>ValidCredentials</AuthenticationResultCode> 
    <TraceId> 
    dd31ffaf098f4406b7ecdd0da36680ff 
    </TraceId> 
    <ResourceSets> 
    <ResourceSet> 
     <EstimatedTotal>1</EstimatedTotal> 
     <Resources> 
     <Location> 
      <Name>1 Microsoft Way, Redmond, WA 98052</Name> 
      <Point> 
      <Latitude>47.640568390488625</Latitude> 
      <Longitude>-122.1293731033802</Longitude> 
      </Point> 
      <BoundingBox> 
      <SouthLatitude>47.636705672917948</SouthLatitude> 
      <WestLongitude>-122.137016420622</WestLongitude> 
      <NorthLatitude>47.6444311080593</NorthLatitude> 
      <EastLongitude>-122.1217297861384</EastLongitude> 
      </BoundingBox> 
      <EntityType>Address</EntityType> 
      <Address> 
      <AddressLine>1 Microsoft Way</AddressLine> 
      <AdminDistrict>WA</AdminDistrict> 
      <AdminDistrict2>King Co.</AdminDistrict2> 
      <CountryRegion>United States</CountryRegion> 
      <FormattedAddress>1 Microsoft Way, Redmond, WA 98052</FormattedAddress> 
      <Locality>Redmond</Locality> 
      <PostalCode>98052</PostalCode> 
      </Address> 
      <Confidence>Medium</Confidence> 
      <MatchCode>Good</MatchCode> 
      <GeocodePoint> 
      <Latitude>47.640568390488625</Latitude> 
      <Longitude>-122.1293731033802</Longitude> 
      <CalculationMethod>Interpolation</CalculationMethod> 
      <UsageType>Display</UsageType> 
      <UsageType>Route</UsageType> 
      </GeocodePoint> 
     </Location> 
     </Resources> 
    </ResourceSet> 
    </ResourceSets> 
</Response> 
+0

我需要使用JSON的信息,以便任何人都可以建议我一个方法来转换XML到json .... – 2012-02-02 10:12:39

+1

如果您在请求URL中将o = json更改为o = json,那么数据也可用JSON格式 – ZombieSheep 2012-02-02 10:12:51

+1

不要忘记,您将需要Bing Maps API密钥 - 请转至http://www.bingmapsportal.com/得到一个 – ZombieSheep 2012-02-02 10:13:55

您可以使用网络的由Microsoft提供的服务,根据您提供的经度和纬度返回城市,州和国家。

通过提供链接http://msrmaps.com/TerraService2.asmx

在项目中创建一个Web服务引用我有一个名为服务为myTerraService

myTerraService.TerraServiceSoapClient client = new myTerraService.TerraServiceSoapClient(); 
     client.ConvertLonLatPtToNearestPlaceCompleted += new EventHandler<myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs>(client_ConvertLonLatPtToNearestPlaceCompleted); 
     client.ConvertLonLatPtToNearestPlaceAsync(new myTerraService.LonLatPt { Lat = latitude, Lon = longitude }); 
    } 

    void client_ConvertLonLatPtToNearestPlaceCompleted(object sender, myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs e) 
    { 
     string location = e.Result; // this string will have city, state, country 
    }