2017-08-24 6 views
0

ユーザーがオートコンプリートを使用して場所を入力し、Googleの多数の場所関連APIのいずれかを使用できるようにするJavascriptを書きたいと考えています。ユーザからの入力は、国内タウンまたは名、道路名、完全なアドレス(ドア数 +道路名)、(例えばレストランなど)場所名前になりますまたは郵便番号。この入力により私のニーズに合ったGoogleロケーションAPI

Iは緯度経度をキャプチャしたい、そして可能な場合提供郵便番号/郵便番号。

この件ではAPIが無数にあり、時には間違った結果を出すgoogle.maps.Geocoderで試してみました(正しく自動完成した町のランダムなLat/Long情報を渡します)。私のニーズに最も適したものをお教えください。

は、このコードは、コルドバのモバイルアプリケーション開発のために働くあなたに

+0

https://developers.google.com/maps/documentation/javascript/places-autocompleteからダウンロードforwardGeocodeプラグイン –

答えて

0
var lat=0, lng=0; 

    document.addEventListener("deviceready", index, false); 

    function index(){ 
     initialMap(); 
     $("#pac-input").on("change",function(){ 
      setTimeout(function(){ 
       address = $("#pac-input").val(); 
       nativegeocoder.forwardGeocode(getlatlngFetch, faild, address); 
      },600); 
     }); 
    } 

    function initialMap() { 
     var input = document.getElementById('pac-input'); 

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

     var infowindow = new google.maps.InfoWindow(); 

     autocomplete.addListener('place_changed', function() { 
      var place = autocomplete.getPlace(); 
      if (!place.geometry) { 
      window.alert("No details available for input: '" + place.name + "'"); 
      return; 
      } 
     }); 
    } 

    function getlatlngFetch(coordinates){ 
     lat = coordinates.latitude; 
     lng = coordinates.longitude; 
     alert("Lattitude= "+lat+" Longitude= "+lng); 
    } 

function faild(){ 
    alert('Failed'); 
} 

をありがとうございました。 https://www.npmjs.com/package/cordova-plugin-nativegeocoder

関連する問題