这是我的代码。这里的地图对我来说工作正常,仅针对输入框自动完成问题对我不起作用。请指导我解决这个问题....................... .................................................. ........
**HTML**
<input type="text"name="newWardName" id="newWardName" placeholder="Enter Ward Name"/>
<div>
<div id="googleMap" ></div>
<input id="latitudeId" name="latitudeName" placeholder="Latitude"/>
<input id="longitudeId" name="longitudeName" placeholder="Longitude"/>
</div>
**JavaScript**
function initialize()
{
geocoder = new google.maps.Geocoder();
var myCenter=new google.maps.LatLng(12.961735, 77.588195);
var mapProp = {
center:myCenter,
zoom:12,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
var input = document.getElementById('newWardName');
var autocomplete = new google.maps.places.Autocomplete(input, {
types: ["geocode"]
});
autocomplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
console.log("on click of map", (event.latLng));
});
}
var marker;
function placeMarker(location) {
if (!marker) {
marker = new google.maps.Marker({
position: location,
map: map
});
} else {
marker.setPosition(location);
}
document.getElementById("latitudeId").value = location.lat();
document.getElementById("longitudeId").value = location.lng();
}
提前致谢 数学
答案 0 :(得分:0)
最后我发现了我的错误。调用地图api两次,现在工作正常。