Googleマップ(場所)の自動補完APIにアクセスするために必要な動的テキスト入力があります。Googleマップの自動配列を動的配列
「開始」、「終了」、および「第1のウェイポイント」(動的ではない)はうまくいきますが、4時間後には動的テキスト入力をオートコンプリートにするのに苦労しています。そして、Googleの答えに似て何かを見つけることができません。
これは私がこれまで持っているものです: Javascriptを:
function initialize() {
var options = {
componentRestrictions: {
country: "au"
}
};
var inputs = document.getElementById('start');
var autocompletes = new google.maps.places.Autocomplete(inputs, options);
var inpute = document.getElementById('end');
var autocompletee = new google.maps.places.Autocomplete(inpute, options);
var waypoints = document.getElementsByName("waypoints[]");
for (var i = 0; i < waypoints.length; i++) {
var inputw = waypoints[i];
var autocompletew = new google.maps.places.Autocomplete(inputw, options);
}
directionsDisplay = new google.maps.DirectionsRenderer();
var melbourne = new google.maps.LatLng(-31.953512, 115.857048);
var myOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: melbourne
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
HTML:
var counter = 1;
var limit = 10;
var i = 1;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = (counter + 1) + "<input type=text name=waypoints[] autocomplete=on>";
document.getElementById(divName).appendChild(newdiv);
counter++;
i++;
var inputw = waypoints[i];
var autocompletew = new google.maps.places.Autocomplete(inputw, options);
}
}
私はPHPでかなり堪能していますが、それでも非常にJavascriptを学びました。
関連の質問:[Googleプレイスオートコンプリートに最後の入力のマーカーしか表示されないのはなぜですか?](http://stackoverflow.com/questions/21335716/why-only-the-marker-of-the-last-input-appears -in-google-places-autocomplete) – geocodezip
関連する質問:[Google Apiは追加入力で作業していません](http://stackoverflow.com/questions/33899125/google-api-not-working-on-appended-input) – geocodezip
あなたの質問にはHTMLはありません。 "HTML"とマークされたコードは、それがどのように呼び出され/使用されているかの表示がない、追加のJavaScriptです。あなたの問題を示す[mcve]を提供してください。 – geocodezip