/// <summary> /// Получить координаты по запросу. /// </summary> /// <param name="streetName">Запрос (адрес или иное географическое название).</param> /// <returns>Координаты запроса или null, если результат пустой.</returns> public Location GetGeocoding(string streetName) { GeocodeJsonReply reply = googleService.GetGeocoding(streetName); if ("ZERO_RESULTS".Equals(reply.Status)) { return(null); } else { double lat = reply.Results[0].Geometry.Location.Lat; double lng = reply.Results[0].Geometry.Location.Lng; return(new Location(lat, lng)); } }
private string getStreetName(Location location) { string lat = location.Lat.ToString(); string lng = location.Lng.ToString(); try { GeocodeJsonReply geoCoding = restService.GetGeocoding(lat, lng); if ("ZERO_RESULTS".Equals(geoCoding.Status)) { return(lat + ";" + lng); } else { return(geoCoding.Results[0].AddressComponents.First(address => address.Types[0].Equals("route")).LongName); } } catch (WebException ex) { return(lat + ";" + lng); } }