マップを表示せずにautocomplete api googleマップから緯度と経度を取得しようとしています。スクリプトではオートコンプリートはうまくいきますが、私は緯度と経度を取得できません。Google map api get地図なしのオートコンプリートからの緯度と経度
<script type="text/javascript">
function initialize() {
var options = {
types: ['(cities)']
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
var geocoder = new google.maps.Geocoder();
var address = autocomplete;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert(latitude);
}
});
</script>
今のようには思われません。 Googleマップのドキュメントでは、「地図を表示しなくてもプレイスオートコンプリートを使用できます。地図を表示する場合は、Googleマップでなければなりません。地図なしでプレイスオートコンプリートサービスから予測を表示するときは、 Googleのロゴによって。 これはAPIのドキュメントから取得したものです。https://developers.google.com/places/documentation/autocomplete –