为 Google 地图创建客户标记
Creating a customer marker for Google Maps
我正在尝试为我目前在 Google 地图上的图钉创建一个新标记。我已经按照文档中的示例进行操作,但仍然得到旧的红色别针。
这是标记特定的代码:
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
这是整个地图脚本。
google.maps.event.addDomListener(window, 'load', init);
function init() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(51.521616, -0.102589),
styles: [ {"featureType":"all", "stylers":[ {"saturation":0}, {"hue":"#e7ecf0"} ] }, {"featureType":"road", "stylers":[ {"saturation":-70} ] }, {"featureType":"transit", "stylers":[ {"visibility":"on"} ] }, {"featureType":"poi", "stylers":[ {"visibility":"off"} ] }, {"featureType":"water", "stylers":[ {"visibility":"simplified"}, {"saturation":-60} ] }]
};
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var mapElement = document.getElementById('map');
var map = new google.maps.Map(mapElement, mapOptions);
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
我哪里做错了?这与我添加的其他地图选项有关吗?
我正在使用 Google 地图 API v3
您的代码中有错字(您正在覆盖 "marker",应该是 "image")。变化:
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
收件人:
var image = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
google.maps.event.addDomListener(window, 'load', init);
function init() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(51.521616, -0.102589),
styles: [{
"featureType": "all",
"stylers": [{
"saturation": 0
}, {
"hue": "#e7ecf0"
}]
}, {
"featureType": "road",
"stylers": [{
"saturation": -70
}]
}, {
"featureType": "transit",
"stylers": [{
"visibility": "on"
}]
}, {
"featureType": "poi",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "water",
"stylers": [{
"visibility": "simplified"
}, {
"saturation": -60
}]
}]
};
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var mapElement = document.getElementById('map');
var map = new google.maps.Map(mapElement, mapOptions);
var image = 'http://maps.google.com/mapfiles/ms/icons/blue.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
}
html,
body,
#map {
height: 100%;
width: 100%;
}
<script src="http://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>
我正在尝试为我目前在 Google 地图上的图钉创建一个新标记。我已经按照文档中的示例进行操作,但仍然得到旧的红色别针。
这是标记特定的代码:
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
这是整个地图脚本。
google.maps.event.addDomListener(window, 'load', init);
function init() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(51.521616, -0.102589),
styles: [ {"featureType":"all", "stylers":[ {"saturation":0}, {"hue":"#e7ecf0"} ] }, {"featureType":"road", "stylers":[ {"saturation":-70} ] }, {"featureType":"transit", "stylers":[ {"visibility":"on"} ] }, {"featureType":"poi", "stylers":[ {"visibility":"off"} ] }, {"featureType":"water", "stylers":[ {"visibility":"simplified"}, {"saturation":-60} ] }]
};
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var mapElement = document.getElementById('map');
var map = new google.maps.Map(mapElement, mapOptions);
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
我哪里做错了?这与我添加的其他地图选项有关吗?
我正在使用 Google 地图 API v3
您的代码中有错字(您正在覆盖 "marker",应该是 "image")。变化:
var marker = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
收件人:
var image = 'marker.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
google.maps.event.addDomListener(window, 'load', init);
function init() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(51.521616, -0.102589),
styles: [{
"featureType": "all",
"stylers": [{
"saturation": 0
}, {
"hue": "#e7ecf0"
}]
}, {
"featureType": "road",
"stylers": [{
"saturation": -70
}]
}, {
"featureType": "transit",
"stylers": [{
"visibility": "on"
}]
}, {
"featureType": "poi",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "water",
"stylers": [{
"visibility": "simplified"
}, {
"saturation": -60
}]
}]
};
var myLatLng = new google.maps.LatLng(51.521616, -0.102589);
var mapElement = document.getElementById('map');
var map = new google.maps.Map(mapElement, mapOptions);
var image = 'http://maps.google.com/mapfiles/ms/icons/blue.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});
}
html,
body,
#map {
height: 100%;
width: 100%;
}
<script src="http://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>