我有以下Javascript,其中包括標準Google Maps API initialize()
函數和自定義addMarker()
函數。地圖加載正常,但標記不會添加到地圖中。使用Google Maps API添加標記功能
<script type="text/javascript">
// Standard google maps function
function initialize() {
var myLatlng = new google.maps.LatLng(40.779502, -73.967857);
var myOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
// Function for adding a marker to the page.
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map
});
}
// Testing the addMarker function
CentralPark = new google.maps.LatLng(37.7699298, -122.4469157);
addMarker(CentralPark);
</script>
查看本教程以獲取完整解決方案。 http://webdesignpluscode.blogspot.com.tr/2016/02/how-to-add-markerpin-on-google-map.html –