此问题之前已经得到解答,但是当我实施所述解决方案时,它对我不起作用。任何指导将不胜感激:)
function geolocateFunc(){
GMaps.geolocate({
success: function(position) {
map.setCenter(position.coords.latitude,position.coords.longitude);
map.addMarker({
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
scaledSize: new google.maps.Size(150, 150),
lat: position.coords.latitude,
lng: position.coords.longitude,
infoWindow: {content: "<strong>This is my current location</strong>"},
});
},
error: function(error) {
alert('Geolocation failed: '+error.message);
},
not_supported: function() {
alert("Your browser does not support geolocation");
},
always: function() {
alert("Done!");
}
});
}
我尝试了scaledSize函数,它看不到工作
答案 0 :(得分:0)
尝试实例化新的Marker而不是addMarker方法。如果仍然没有快乐,看看&#34;优化&#34;属性设置会产生差异
礼貌w3schools: -
<!DOCTYPE html>
<html>
<body>
<div id="map" style="width:100%;height:500px"></div>
<script>
function myMap() {
var mapCanvas = document.getElementById("map");
var myCenter = new google.maps.LatLng(51.508742,-0.120850);
var mapOptions = {center: myCenter, zoom: 5};
var map = new google.maps.Map(mapCanvas,mapOptions);
var pinkball = {size: new google.maps.Size(100, 100),
scaledSize: new google.maps.Size(100, 100),
url: "pinkball.png"};
var marker = new google.maps.Marker({
position: myCenter,
icon: pinkball
});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
<!--
To use this code on your website, get a free API key from Google.
Read more at: https://www.w3schools.com/graphics/google_maps_basic.asp
-->
</body>
</html>