getPlace()
戻り、この構造:
{"address_components":[{"long_name":"Dallas","short_name":"Dallas","types":["locality","political"]},{"long_name":"Dallas County","short_name":"Dallas County","types":["administrative_area_level_2","political"]},{"long_name":"Texas","short_name":"TX","types":["administrative_area_level_1","political"]},{"long_name":"United States","short_name":"US","types":["country","political"]}],"adr_address":"<span class=\"locality\">Dallas</span>, <span class=\"region\">TX</span>, <span class=\"country-name\">USA</span>","formatted_address":"Dallas, TX, USA","geometry":{"location":{"lat":32.7766642,"lng":-96.79698789999998},"viewport":{"south":32.617537,"west":-96.99894130000001,"north":33.0237921,"east":-96.46373790000001}},"icon":"https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png","id":"fa589a36153613fc17b0ebaebbea7c1e31ca62f0","name":"Dallas","photos":[{"height":2322,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/103240547556009569847/photos\">Robert Rogers</a>"],"width":4128},{"height":728,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/103202508011395907641/photos\">Blake Margolis RowlettSachseScanner</a>"],"width":1440},{"height":1579,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/110350056655658805900/photos\">Ramil Soy</a>"],"width":2807},{"height":2366,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/111265500346815453367/photos\">Wolfgang Demino</a>"],"width":3619},{"height":4387,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/103960188949347184478/photos\">Thang Tran</a>"],"width":6000},{"height":2304,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/117980955401126505428/photos\">Nymisha Bandi</a>"],"width":4096},{"height":2221,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/113732984326979786649/photos\">Volkan Yuksel</a>"],"width":5692},{"height":665,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/101875825735695083663/photos\">Accounting Department</a>"],"width":1000},{"height":3519,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/102844598608092286357/photos\">LCP360 Production</a>"],"width":5760},{"height":1152,"html_attributions":["<a href=\"https://maps.google.com/maps/contrib/105626597651962458040/photos\">K. Osgood</a>"],"width":2048}],"place_id":"ChIJS5dFe_cZTIYRj2dH9qSb7Lk","reference":"CnRsAAAAd4lD76ntfuCVsOakSCHjeWZEdxuVIKsnv86z3u9Fq1A12QTRvj6SSS4O4ZE9Apvq_wWT8r4ux3lT8FDvIDD6EWNKHiUVyhhxw-1yMClXawE20mV8_xPGXz2UKPoKSSbZmqH1rzlIqVTuOeKMt_5OBRIQLtW-4AspRKSG4Mv_fEbrERoUrJyRcYEoY4CbwPyC77PXO70_1_c","scope":"GOOGLE","types":["locality","political"],"url":"https://maps.google.com/?q=Dallas,+TX,+USA&ftid=0x864c19f77b45974b:0xb9ec9ba4f647678f","utc_offset":-300,"vicinity":"Dallas","html_attributions":[]}
だから我々は簡単にあなたが望む結果を得るために詳細を解析できます。
たとえば、短い名前のみを示す元のサンプルのフォークを確認します。 http://plnkr.co/edit/6egntT9xl4eZVJg6HoWj?p=preview
次に、要素の値を結果の代わりに.nameに設定します。
Plunkerは、私はちょうどオートコンプリートサービスからフォーマットされた文字列にテキストボックスを設定した行をコメントアウトnewAutoComplete
機能で
編集
を更新しました。
//scope.ngAutocomplete = element.val(); // the formatted string is in the text box.
scope.ngAutocomplete = scope.details.name; // we just want the name field.
element[0].value = scope.details.name; // you could use other parts of the object above if need be.
いいえ入力したスロットを「結果」のdivではなく都市名に更新する必要があります。 – rayjonnes
私は: を意味します)1)「Choose Departure City」(Googleオートコンプリート入力)のプレースホルダを入力しました。 2)私たちはGoogleの提案のリストから "Dallas"を入力して "Dallas、TX、United States"を選択します。 3)そして同じ入力で "Choose Departure City"が "Dallas" あなたの解決策ではまだ "Dallas、TX、United States"で、別の部門を設定して "Dallas"を設定しますが、もう一度入力スロットをDallasにする必要があります(都市のみを表示するように構成されています) – rayjonnes
私は'address_components'は入力中の検索語の特異性に応じて変わります。 "Dallas、TX、United States"の検索結果から返された 'details1.address_components'を使用して、上記の文字列(" Dallas、TX、United States ")を作成するための簡単なプランナーを得ます。http://embed.plnkr.co/ avOdHiDY657dE9TFcycM / –