Windows Phone ReverseGeocoding to get Address from Lat and Long

依然范特西╮ 提交于 2019-12-04 02:32:04

问题


i am using the following service reference to get location details from latitude and longnitude

http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc

i added the above URL to my Service reference class and try to get the location details by calling the below method

 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;

           }

but i am getting the following error message

  1. GeoCodeService.GeoCodeServiceClient does not contain a definition for ReverseGeocode and no extension method

  2. GeoCodeService.GeoCodeServiceClient could not be found.

help me in solving the problem.and also tell me is this a best way to find location details .


回答1:


In Windows Phone 8 you have built-in API for reverse geocoding, without the need of adding a Service Reference to Bing Maps:

        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();


来源:https://stackoverflow.com/questions/16685088/windows-phone-reversegeocoding-to-get-address-from-lat-and-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!