【发布时间】:2020-02-25 16:20:54
【问题描述】:
我已将地图添加到我的网站,但似乎无法添加带有地图的搜索框来搜索位置。我在下面给出了用于添加地图的代码。有人可以帮忙在代码中添加搜索框吗?
<div id="googleMap" style="width:100%;height:400px;"></div>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(12.9716, 77.5946),
zoom:10,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(e) {
placeMarker(e.latLng, map);
document.getElementById("latitude").value = e.latLng.lat();
document.getElementById("longitude").value = e.latLng.lng();
});
function placeMarker(position, map) {
var marker = new google.maps.Marker({
position: position,
map: map
});
map.panTo(position);
}
}
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=myMap"></script>
【问题讨论】:
-
你看到example in the documentation了吗?您尝试将其添加到代码中时遇到了什么麻烦?请提供一个 minimal reproducible example 来证明您的问题。
标签: javascript html google-maps