如何更改Gmaps.js在Google地图中使用的图标?
How can I use the latest version of GMaps.js to change the pin icon I set in code?
如何使用最新版本的GMaps.js更改我在代码中设置的图钉图标?
Here's what I'm trying to do:
这是我正在尝试做的事情:
$('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"
}
});
}
}
});
});
When running this script, the following errors flare up in Firebug's console:
运行此脚本时,Firebug控制台中会出现以下错误:
"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined"
"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined"
I don't understand why it's trying to HTTP GET that URL since I've never invoked it anywhere in the code.
我不明白为什么它试图HTTP GET该URL,因为我从未在代码中的任何地方调用它。
1 个解决方案
#1
5
Changing the icon on a marker is quite simple.
更改标记上的图标非常简单。
If you read the documentation, notice it says:
如果您阅读文档,请注意:
Also, createMarker accepts any option defined in google.maps.MarkerOptions and any marker event defined in google.maps.Marker ('Events' section).
此外,createMarker接受google.maps.MarkerOptions中定义的任何选项以及google.maps.Marker('Events'部分)中定义的任何标记事件。
And if you read the Google documentation, it's just a matter of calling:
如果您阅读Google文档,则只需要致电:
icon: "some-url-here"
In my case it was:
在我的情况下它是:
$('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());
}
}
});
});
更多相关文章
- 在Ajax请求后添加了自闭标记
- 删除一个HTML标记,但是保留innerHtml
- 【HTML&CSS】【7】网址栏左侧出现的图标Icon
- 在Paragraph标记中添加“名称”以使用POST
- 未捕获的ReferenceError:函数未定义,它标记
- 布局的标记建议和一些更一般的问题
- js去除html标记的测试问题。很多分!
- 当锚标记被单击时,角值从一个页面传递到另一个页面
- 如何为django模板中的标记创建动态id