コード例 #1
0
ファイル: MapsService.cs プロジェクト: Makzz90/VKClient_re
 public void ReverseGeocodeToAddress(double latitude, double longitude, Action <BackendResult <string, ResultCode> > callback)
 {
     JsonWebRequest.SendHTTPRequestAsync(string.Format(MapsService._reverseGeocodeUriFormat, this.CoordinatesToString(latitude, longitude), CultureInfo.CurrentCulture), (Action <JsonResponseData>)(data =>
     {
         if (!data.IsSucceeded)
         {
             callback(new BackendResult <string, ResultCode>(ResultCode.CommunicationFailed));
         }
         else
         {
             GoogleGeocode googleGeocode = JsonConvert.DeserializeObject <GoogleGeocode>(data.JsonString);
             if (googleGeocode.results != null && googleGeocode.results.Count > 0)
             {
                 GoogleGeocodeResult googleGeocodeResult = googleGeocode.results.FirstOrDefault <GoogleGeocodeResult>((Func <GoogleGeocodeResult, bool>)(r =>
                 {
                     if (r.address_components != null)
                     {
                         return(r.address_components.Count > 0);
                     }
                     return(false);
                 }));
                 if (googleGeocodeResult != null)
                 {
                     callback(new BackendResult <string, ResultCode>(ResultCode.Succeeded, googleGeocodeResult.formatted_address));
                     return;
                 }
             }
             callback(new BackendResult <string, ResultCode>(ResultCode.UnknownError));
         }
     }), null);
 }
コード例 #2
0
ファイル: MapsService.cs プロジェクト: Makzz90/VKClient_re
 public void ReverseGeocode(double latitude, double longitude, Action <BackendResult <GoogleGeocodeResponse, ResultCode> > callback)
 {
     JsonWebRequest.SendHTTPRequestAsync(string.Format(MapsService._reverseGeocodeUriFormat, this.CoordinatesToString(latitude, longitude), CultureInfo.CurrentCulture), (Action <JsonResponseData>)(data =>
     {
         if (!data.IsSucceeded)
         {
             callback(new BackendResult <GoogleGeocodeResponse, ResultCode>(ResultCode.CommunicationFailed));
         }
         else
         {
             GoogleGeocode googleGeocode = JsonConvert.DeserializeObject <GoogleGeocode>(data.JsonString);
             if (googleGeocode.results != null && googleGeocode.results.Count > 0)
             {
                 GoogleGeocodeResult googleGeocodeResult = googleGeocode.results.FirstOrDefault <GoogleGeocodeResult>((Func <GoogleGeocodeResult, bool>)(r =>
                 {
                     if (r.address_components != null)
                     {
                         return(r.address_components.Count > 0);
                     }
                     return(false);
                 }));
                 if (googleGeocodeResult != null)
                 {
                     List <GoogleAddressComponent> addressComponents = googleGeocodeResult.address_components;
                     string str1 = "";
                     string str2 = "";
                     string str3 = "";
                     string str4 = "";
                     string str5 = "";
                     foreach (GoogleAddressComponent addressComponent in addressComponents)
                     {
                         if (addressComponent.types != null && addressComponent.types.Count != 0)
                         {
                             List <string> types = addressComponent.types;
                             if (types.Contains("route") && string.IsNullOrEmpty(str1))
                             {
                                 str1 = addressComponent.long_name;
                             }
                             else if (types.Contains("administrative_area_level_1") && string.IsNullOrEmpty(str2))
                             {
                                 str2 = addressComponent.long_name;
                             }
                             else if (types.Contains("administrative_area_leve_2") && string.IsNullOrEmpty(str3))
                             {
                                 str3 = addressComponent.long_name;
                             }
                             else if (types.Contains("country") && string.IsNullOrEmpty(str4))
                             {
                                 str4 = addressComponent.long_name;
                                 str5 = addressComponent.short_name;
                             }
                         }
                     }
                     callback(new BackendResult <GoogleGeocodeResponse, ResultCode>(ResultCode.Succeeded, new GoogleGeocodeResponse()
                     {
                         Route = str1,
                         AdministrativeArea1 = str2,
                         AdministrativeArea2 = str3,
                         Country             = str4,
                         CountryISO          = str5
                     }));
                     return;
                 }
             }
             callback(new BackendResult <GoogleGeocodeResponse, ResultCode>(ResultCode.UnknownError));
         }
     }), null);
 }