#php #google_maps_api #google_maps
https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $latitude .",". $longitude ."&sensor=false&key=API_KEY Проблема такая, получаю в ответ неправильный адрес, как исправить? Пример того, что я получаю { "plus_code" : { "compound_code" : "5C9R+3C Yerevan, Armenia", "global_code" : "8HG65C9R+3C" }, "results" : [ { "address_components" : [ { "long_name" : "жилое", "short_name" : "жилое", "types" : [ "premise" ] }, { "long_name" : "Bangladesh", "short_name" : "Bangladesh", "types" : [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "locality", "political" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "жилое, Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.1678554, "lng" : 44.4411725 }, "southwest" : { "lat" : 40.1674516, "lng" : 44.4409767 } }, "location" : { "lat" : 40.1676558, "lng" : 44.4410813 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 40.1690024802915, "lng" : 44.4424235802915 }, "southwest" : { "lat" : 40.1663045197085, "lng" : 44.4397256197085 } } }, "place_id" : "ChIJN4orDd-9akARr_CHIzBo7uE", "types" : [ "premise" ] }, { "address_components" : [ { "long_name" : "Unnamed Road", "short_name" : "Unnamed Road", "types" : [ "route" ] }, { "long_name" : "Bangladesh", "short_name" : "Bangladesh", "types" : [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "locality", "political" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "Unnamed Road, Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.1678113, "lng" : 44.4409177 }, "southwest" : { "lat" : 40.1671363, "lng" : 44.4394916 } }, "location" : { "lat" : 40.1673747, "lng" : 44.440349 }, "location_type" : "GEOMETRIC_CENTER", "viewport" : { "northeast" : { "lat" : 40.1688227802915, "lng" : 44.4415536302915 }, "southwest" : { "lat" : 40.1661248197085, "lng" : 44.4388556697085 } } }, "place_id" : "ChIJX5kLet-9akARxu92iLmBBCk", "types" : [ "route" ] }, { "address_components" : [ { "long_name" : "B1", "short_name" : "B1", "types" : [ "neighborhood", "political" ] }, { "long_name" : "Malatia-Sebastia", "short_name" : "Malatia-Sebastia", "types" : [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "locality", "political" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "B1, Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.1738564, "lng" : 44.4460917 }, "southwest" : { "lat" : 40.1651662, "lng" : 44.4371009 } }, "location" : { "lat" : 40.1698302, "lng" : 44.441828 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 40.1738564, "lng" : 44.4460917 }, "southwest" : { "lat" : 40.1651662, "lng" : 44.4371009 } } }, "place_id" : "ChIJE4fvRt69akARZwyHPF6rPiA", "types" : [ "neighborhood", "political" ] }, { "address_components" : [ { "long_name" : "Malatia-Sebastia", "short_name" : "Malatia-Sebastia", "types" : [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "locality", "political" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "Malatia-Sebastia, Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.2256632, "lng" : 44.48988139999999 }, "southwest" : { "lat" : 40.1447431, "lng" : 44.3619347 } }, "location" : { "lat" : 40.1686452, "lng" : 44.45749199999999 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 40.2256632, "lng" : 44.48988139999999 }, "southwest" : { "lat" : 40.1447431, "lng" : 44.3619347 } } }, "place_id" : "ChIJcabfJdG9akARS3WuMhvvZcI", "types" : [ "political", "sublocality", "sublocality_level_1" ] }, { "address_components" : [ { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "locality", "political" ] }, { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.2426667, "lng" : 44.6150493 }, "southwest" : { "lat" : 40.0641141, "lng" : 44.3620849 } }, "location" : { "lat" : 40.1872023, "lng" : 44.515209 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 40.2426667, "lng" : 44.6150493 }, "southwest" : { "lat" : 40.0641141, "lng" : 44.3620849 } } }, "place_id" : "ChIJW4v8uNqiakARalLah655FD0", "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "Yerevan", "short_name" : "Yerevan", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "Yerevan, Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 40.261712, "lng" : 44.66696109999999 }, "southwest" : { "lat" : 40.08440600000001, "lng" : 44.416932 } }, "location" : { "lat" : 40.1794197, "lng" : 44.5408413 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 40.261712, "lng" : 44.66696109999999 }, "southwest" : { "lat" : 40.08440600000001, "lng" : 44.416932 } } }, "place_id" : "ChIJc-dHAcOiakAR9TDRSvqQzRU", "types" : [ "administrative_area_level_1", "political" ] }, { "address_components" : [ { "long_name" : "Armenia", "short_name" : "AM", "types" : [ "country", "political" ] } ], "formatted_address" : "Armenia", "geometry" : { "bounds" : { "northeast" : { "lat" : 41.300993, "lng" : 46.6342219 }, "southwest" : { "lat" : 38.840244, "lng" : 43.4472601 } }, "location" : { "lat" : 40.069099, "lng" : 45.038189 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 41.300993, "lng" : 46.6342219 }, "southwest" : { "lat" : 38.840244, "lng" : 43.4472601 } } }, "place_id" : "ChIJx7pz54RWFUARIy2C63p1tNA", "types" : [ "country", "political" ] } ], "status" : "OK" } вместо номера и адреса дома получаю "жилой дом". К примеру на сайте https://www.gps-coordinates.net , который также использует гугл мапс, все адреса правильно выводятся
Ответы
Ответ 1
По данному району Еревана у Гугл нет информации о номерах домов. https://www.google.ru/maps/@40.1676681,44.440202,19.39z Зато на ОСМ есть номера домов https://www.openstreetmap.org/#map=19/40.16770/44.44048 Тут 2 варианта решения. 1. Сделать геокодер на основе ОСМ и других доступных данных на интересующую область. Плюс подхода в том, что вы получаете независимость, гибкость, возможность редактировать и дополнять информацию, улучшая результат. 2. Использовать готовые сторонние сервисы, типа https://opencagedata.com Плюс подхода в быстроте подключения. Не нужно разрабатывать API и анализировать данные. Можно сочетать оба варианта, проверяя результат, выводить лучший.Ответ 2
У гугла такое может быть, не использовав другие сервисы вы не сможете определить адрес. http://joxi.ru/1A5Go11tDQjlqm т.е. даже на google maps нет адресов у зданий. А https://www.gps-coordinates.net/ использует https://opencagedata.com/ что вы можете собственно и использовать вместо гугла, сервис даёт 2500 запросов в день бесплатно, гугл даёт 70 000 запросов в месяц бесплатно. Посмотреть работу демо можно тут https://opencagedata.com/demo
Комментариев нет:
Отправить комментарий