2017-01-12 143 views
-1

我想使用自定義標記(圖像)到我的地圖。使用自定義標記

目前我的代碼看起來是這樣的:

<script> 
function myMap() { 
    var mapCanvas = document.getElementById("map"); 
    var mapOptions = { 
    center: new google.maps.LatLng(47.3921611, 8.4957963), 
    zoom: 14 
    } 

    var map = new google.maps.Map(mapCanvas, mapOptions); 
} 
</script> 

我怎麼能實現它向我的代碼?

+0

有沒有在發佈代碼的任何標記。 – geocodezip

+0

@geocodezip如果有標記,則不會有任何問題。 – Reza

+0

https://developers.google.com/maps/documentation/javascript/examples/icon-simple – geocodezip

回答

1

Google's "simple Marker" example

var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; 
    var beachMarker = new google.maps.Marker({ 
     position: {lat: -33.890, lng: 151.274}, 
     map: map, 
     icon: image 
    }); 

代碼段與它添加到代碼中你的問題:

function myMap() { 
 
    var mapCanvas = document.getElementById("map"); 
 
    var mapOptions = { 
 
    center: new google.maps.LatLng(47.3921611, 8.4957963), 
 
    zoom: 14 
 
    } 
 

 
    var map = new google.maps.Map(mapCanvas, mapOptions); 
 
    var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; 
 
    var beachMarker = new google.maps.Marker({ 
 
    position: map.getCenter(), 
 
    map: map, 
 
    icon: image 
 
    }); 
 
} 
 
google.maps.event.addDomListener(window, 'load', myMap);
html, 
 
body, 
 
#map { 
 
    height: 100%; 
 
    width: 100%; 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map"></div>

+0

這就是我想要的。非常感謝! – Reza