我甚至无法淡化 LatLng 位置的基本标记,我不确定如何修复它。每当我尝试放置标记时,整个div 标签和地图都会消失。
<div id="googleMap" style="width:100%;height:400px;"></div>
<script>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(-36.934601, 174.915836),
zoom:15,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDRqDMSVnEAKKE7vPz3cWiJ9Ge6lLLBtQ4&callback=myMap"></script>
</div>
你必须定义 myLatLng
var myLatLng = {lat:-36.934601, lng: 174.915836};
完整的代码变为:
<div id="googleMap" style="width:100%;height:400px;"></div>
<script>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(-36.934601, 174.915836),
zoom:15,
};
var myLatLng = {lat:-36.934601, lng: 174.915836};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDRqDMSVnEAKKE7vPz3cWiJ9Ge6lLLBtQ4&callback=myMap"></script>
</div>