API Google Map Place: опция автозаполнения и событие place_changed возвращают разные названия регионов - PullRequest
0 голосов
/ 02 марта 2020

Я использую Google Map API для своего приложения.

Я настроил поиск для автозаполнения следующим образом. Как вы можете видеть, если я наберу "Smileclub Hair Diner", то получится вариант "Smileclub Hair Diner, Ekkamai 10 Alley, Khlong Tan Nuea, Watthana, Bangkok, Thailand".

enter image description here

Затем я щелкнул эту опцию, чтобы сработало событие place_changed, и я мог получить данные о месте на стороне клиента.

autocomplete = new google.maps.places.Autocomplete(input);

// autocomplete action
google.maps.event.addListener(autocomplete, 'place_changed', function() {
  var place = autocomplete.getPlace()
  console.log('place %o', place).
});
{
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "5/1",
            "short_name" : "5/1",
            "types" : [ "street_number" ]
         },
         {
            "long_name" : "Ekkamai 10 Alley",
            "short_name" : "Ekkamai 10 Alley",
            "types" : [ "route" ]
         },
         {
            "long_name" : "Khwaeng Khlong Tan Nuea",
            "short_name" : "Khwaeng Khlong Tan Nuea",
            "types" : [ "sublocality_level_2", "sublocality", "political" ]
         },
         {
            "long_name" : "Khet Watthana",
            "short_name" : "Khet Watthana",
            "types" : [ "sublocality_level_1", "sublocality", "political" ]
         },
         {
            "long_name" : "Krung Thep Maha Nakhon",
            "short_name" : "Krung Thep Maha Nakhon",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "Thailand",
            "short_name" : "TH",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "10110",
            "short_name" : "10110",
            "types" : [ "postal_code" ]
         }
      ],
      "adr_address" : "\u003cspan class=\"street-address\"\u003e5/1 Ekkamai 10 Alley\u003c/span\u003e, \u003cspan class=\"extended-address\"\u003eKhwaeng Khlong Tan Nuea\u003c/span\u003e, \u003cspan class=\"locality\"\u003eKhet Watthana\u003c/span\u003e, \u003cspan class=\"region\"\u003eKrung Thep Maha Nakhon\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e10110\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eThailand\u003c/span\u003e",
      "formatted_address" : "5/1 Ekkamai 10 Alley, Khwaeng Khlong Tan Nuea, Khet Watthana, Krung Thep Maha Nakhon 10110",
      "formatted_phone_number" : "095 515 4526",
      "geometry" : {
         "location" : {
            "lat" : 13.7292008,
            "lng" : 100.5864839
         },
         "viewport" : {
            "northeast" : {
               "lat" : 13.7305444802915,
               "lng" : 100.5877787802915
            },
            "southwest" : {
               "lat" : 13.7278465197085,
               "lng" : 100.5850808197085
            }
         }
      },
      "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
      "id" : "ebf5e99705176c7ba4cf7668c389ed12db608d66",
      "international_phone_number" : "+66 95 515 4526",
      "name" : "Smileclub Hair Diner",
      "photos" : [
         {
            "height" : 3120,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/111846063188053186115\"\u003e蘇開心\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAADUxkVEacPySbgdtnmGIoOxYy4qSsfjd7dx3KvhSO6iYtemXnTebin33HFESh6GqkOrsmPHout5eIkXvxU_rxfqN9Lg8cT0ZEoirHAvWP4e6r4RSMshHmtmnZ5EP_e241EhAyi3hmrptOOwL5AK8Z4GZhGhRqrYiOTnDicV-Co70NjeeDsojkUA",
            "width" : 4160
         },
         {
            "height" : 4608,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/103305500975014133572\"\u003eYanata Chote-panang\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAfMhPhp8MahsDciva73Mih-CUTBns6fDm51zlTX4ujgvqlaP1MfJJIswerujQI5xhPv-95v74Xemhx5slu5-RpQXVGlpN-r0ZXx2BnQLUAZ-HWIyggbaU3MP4TCNYYCopEhB5Ye-VohWCuWewtP6wSN_mGhTC07OhExHRPsWJTYGw_ycH3L4rxg",
            "width" : 3456
         },
         {
            "height" : 3264,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/102286366615406806253\"\u003eTan J Ken\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAYzdseGp3LMf0MvSflshvPe_bJnZKnoB7mlpz6tYDAk3dopJUNPd2TAS6dZVzAWyWhEcX2p8JsD_KOPr4zHAQOgW_XE6SE-ypZrMLaFX50NVA2oQ6M5qMSyfcQHQUeEQvEhDWZcWHz7Q1ljDGy9djEGJdGhT-fdmUOnWnGDfPyu-Vt8cBJpljuA",
            "width" : 2448
         },
         {
            "height" : 3264,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/110641749154852259255\"\u003eEverner Lee\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAZ0I99Hvo5rl1nH-0BrR44AAolFa4NOUPi0467flX5Keg7uVO0phSpjYB-pUdgjVT4GfS0_KlLRAZ-XXmUWQI7HksV1Zu3scAeNUQvEz_lgnJNz_QBLIDa8zBjTwYzux1EhAALb6JFBkJav074UnIBflaGhRdT63xEEXkqNJCu-rBKSn_d3teBQ",
            "width" : 2448
         },
         {
            "height" : 1600,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/102286366615406806253\"\u003eTan J Ken\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAavkTBXlMhUGF8Pjqive0_D-spjXB9fzNk_SQI2Wvvi5LtmyuMaILCBwsZW2P2l77deLiEWID0sR6qWiaGEAt1KUXAI3dzH1ZOvOLS5OcD3R7mzMfYAxABWzltpWhSfkzEhC1JFun-X90VbSTAdk-04s3GhRUeTirnJhrbsY5QF63yDfEQaB-Tw",
            "width" : 1062
         },
         {
            "height" : 3264,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/110641749154852259255\"\u003eEverner Lee\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAsciQVVr6SoTHHa1i3kAG7feOChcGzZK3bTYA9DW-vzwLUuEMifpJUfR1ewEHWRkhcmp-rpSeKCiD-2IbCvAjgSsQoTZwfkJUQgPU7GhwR1X2UhCQAY41Z5iEOPKBG6JOEhDlGI4-bwpbBc4GpqAcpaMHGhSfVQtX1JRoQ2vfH62hDfl399WE5w",
            "width" : 2448
         },
         {
            "height" : 3264,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/110641749154852259255\"\u003eEverner Lee\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAASw1GrBubwZmS3rnrN7ik2P0m8kjEk1XIztfqixZtL8qOAkESa0zlBwfaw16g89P0Yu2_tx6veu0qKdmtSL0yfp8in-ADnPbvamBltaxmAbcemFWtqPDR5Yd-c3g3xJGXEhBdogpO4rQyolBgOhIkVVQmGhRHcjBWC3GKOBPpmsYMdgYg4ru6yQ",
            "width" : 2448
         },
         {
            "height" : 2448,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/102286366615406806253\"\u003eTan J Ken\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAALaBcMD3xWQ67vvjMCi8-ufdVoN4unMvznJTG4bATgalX4tfOIjsUeT3xkfbMB2tpdxfaMqH9tk-u4UBpe75CE3OdSO0NVrVB11pb3cfb7QLlxfWPqdbHhnYZLpNUSHZrEhAGbD_DAHXa7L_72GuvIp5AGhQaUCpNUJJOc6xv_WZkDtSA_28WWw",
            "width" : 3264
         },
         {
            "height" : 3648,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/117656618087341271316\"\u003eWitthawat Kasayapanant\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAKWJeNvHA0itRcfBYj5yoJmMna3gZu4oJEKe02bo4MSaywDOn7v8lgsr4dyGxwdi1l6UHjn9ZEf6hjvbJaf3CQnW4WeweoMVoLt0St_88GkEJsYX-z52ZuvsuUiQl234YEhBY5CaED33yLVGM847tYWi3GhTVmV0p_dauSJns_HQPKD2Wq9QL_Q",
            "width" : 2736
         },
         {
            "height" : 2976,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/100347599586623840612\"\u003ePip Saengplong\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAejIKYFCoAnq-jlBa6nogcKw4G-qkkO9F9tBh_q9aok-9U_4mfMqGuxqClAzji9dabtrRfxOujzF4W8pOprwWEawJKh9CCHW6FttTaAtrSf1TqIP2LaXG91pL-A-38KWQEhD_0daoTPLE7RwTchVANRwgGhTQaYC00Hzs6tIMkQdjPPhkFUlsTg",
            "width" : 3968
         }
      ],
      "place_id" : "ChIJn1XgfLKf4jARcXxBaoeDrgE",
      "plus_code" : {
         "compound_code" : "PHHP+MH Bangkok",
         "global_code" : "7P52PHHP+MH"
      },
      "rating" : 4.6,
      "reference" : "ChIJn1XgfLKf4jARcXxBaoeDrgE",
      "reviews" : [
         {
            "author_name" : "Victor Mau",
            "author_url" : "https://www.google.com/maps/contrib/106992636050613614960/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh4.ggpht.com/-ObsytjClbak/AAAAAAAAAAI/AAAAAAAAAAA/nMBnG0Hdgns/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 4,
            "relative_time_description" : "a month ago",
            "text" : "Very interesting shop with retro style. Good stylist and staff speak good English. 1,000 baht (34 USD) for a man’d haircut is expensive for Thailand.",
            "time" : 1578139203
         },
         {
            "author_name" : "wonderkid 20",
            "author_url" : "https://www.google.com/maps/contrib/106620366680075489590/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh6.ggpht.com/-WUZHH6_HkVs/AAAAAAAAAAI/AAAAAAAAAAA/B-9I9Ku_ioE/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "7 months ago",
            "text" : "Very unique retro hair shop with skilled hair stylists.",
            "time" : 1563371142
         },
         {
            "author_name" : "Buddy T",
            "author_url" : "https://www.google.com/maps/contrib/100790037575662774247/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh5.ggpht.com/-bqc2xJx6an8/AAAAAAAAAAI/AAAAAAAAAAA/01MVU1n7npM/s128-c0x00000000-cc-rp-mo-ba5/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "2 years ago",
            "text" : "Greatest place to cut your hair in Bangkok. The shop is very unique and different from all others. Decorations are dope and they got all the things you need. Best stylists here will take care of you and give you the best they got. They also have shirt, hat, and other accessories for you to shop as well. You’re going to love it!",
            "time" : 1508295239
         },
         {
            "author_name" : "Tarin Doty",
            "author_url" : "https://www.google.com/maps/contrib/101820140751142727607/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh3.ggpht.com/-yZ2ANy31eUk/AAAAAAAAAAI/AAAAAAAAAAA/-w9CLrnXd0w/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 2,
            "relative_time_description" : "a year ago",
            "text" : "We walked in on a whim... looked inside and it was super cute and we weren’t even sure it was a salon. After looking at our hair they said “for you hair length 600 baht for a wash and blow dry.” We contemplated for a little bit but since it was so pricey we thought it would be good. They washed our hair.. not so thoroughly and then sat us down and gave us a bottle of water (which was much appreciated). It took about 5 minutes for them to blow dry our hair.... my hair is curly and still had curls at the top, so I asked him to do a bit more on the top of my hair... he half assedly did it and said ok you’re done! My hair was still very fluffy and was definitely worse than if I had gone to a small shop and paid 150 baht. It’s just super over priced because of the decor. I would NOT recommend this place at all.",
            "time" : 1531536721
         },
         {
            "author_name" : "Robyn Wertman",
            "author_url" : "https://www.google.com/maps/contrib/114652109346962479875/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh5.ggpht.com/-wVlBXquUWcI/AAAAAAAAAAI/AAAAAAAAAAA/L2ig2r4gd6w/s128-c0x00000000-cc-rp-mo-ba4/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "a year ago",
            "text" : "We're from NYC and in Thailand for 28 days. We were looking for a fun place for haircuts for our young sons. These guys did an amazing job and were super friendly!",
            "time" : 1531146467
         }
      ],
      "scope" : "GOOGLE",
      "types" : [ "beauty_salon", "point_of_interest", "establishment" ],
      "url" : "https://maps.google.com/?cid=121178857612082289",
      "user_ratings_total" : 33,
      "utc_offset" : 420,
      "vicinity" : "5/1 Ekkamai 10 Alley, Khlong Tan Nuea, Watthana"
   },
   "status" : "OK"
}

Проблема в том, что я мог видеть «Бангкок» в опции автозаполнения, с другой стороны, данные о месте, которые я получил во время события place_changed, вместо этого возвращает мне «Крунг Тхеп Маха Накхон». Я понимаю, что Krung Thep Maha Nakhon - это настоящее название Бангкока на тайском языке, но мы, иностранцы, обычно называем его Бангкок. Даже если я добавлю параметр параметра region=us в API, это ничего не изменит. Как я могу получить Бангкок вместо Krung Thep Maha Nakhon в качестве возвращаемых данных? Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...