ser*_*erg 3 javascript jquery google-maps
如何使用最新版本的GMaps.js更改我在代码中设置的图钉图标?
这是我正在尝试做的事情:
$('input[name="Address"]').blur(function () {
GMaps.geocode({
address: $('input[name="Address"]').val(),
callback: function (results, status) {
if (status == 'OK') {
var latlng = results[0].geometry.location;
map.setCenter(latlng.lat(), latlng.lng());
map.addMarker({
lat: latlng.lat(),
lng: latlng.lng(),
icon: {
image: "http://i.imgur.com/12312.png"
}
});
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
运行此脚本时,Firebug控制台中会出现以下错误:
"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined"
"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined"
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它试图HTTP GET该URL,因为我从来没有在代码中的任何地方调用它.
更改标记上的图标非常简单.
如果您阅读文档,请注意:
此外,createMarker接受google.maps.MarkerOptions中定义的任何选项以及google.maps.Marker('Events'部分)中定义的任何标记事件.
如果您阅读Google 文档,只需要致电:
icon: "some-url-here"
Run Code Online (Sandbox Code Playgroud)
在我的情况下它是:
$('input[name="Address"]').blur(function () {
GMaps.geocode({
address: $('input[name="Address"]').val(),
callback: function (results, status) {
if (status == 'OK') {
var latlng = results[0].geometry.location;
map.setCenter(latlng.lat(), latlng.lng());
map.addMarker({
lat: latlng.lat(),
lng: latlng.lng(),
icon: "/images/mapicon.png"
});
$('input[name="Longitude"]').val(latlng.lng());
$('input[name="Latitude"]').val(latlng.lat());
}
}
});
});
Run Code Online (Sandbox Code Playgroud)