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());
            }
        }
    });
});

更多相关文章

  1. 在Ajax请求后添加了自闭标记
  2. 删除一个HTML标记,但是保留innerHtml
  3. 【HTML&CSS】【7】网址栏左侧出现的图标Icon
  4. 在Paragraph标记中添加“名称”以使用POST
  5. 未捕获的ReferenceError:函数未定义,它标记
  6. 布局的标记建议和一些更一般的问题
  7. js去除html标记的测试问题。很多分!
  8. 当锚标记被单击时,角值从一个页面传递到另一个页面
  9. 如何为django模板中的标记创建动态id

随机推荐

  1. Android ListView更换点击效果
  2. Android(安卓)UI(TextView)详解
  3. 在android中ScrollView嵌套ScrollView解
  4. Android布局文件属性笔记
  5. Android的Media架构介绍
  6. Android之四大布局
  7. android学习资料整理-----高级篇
  8. android:layout_weight总有你不知道的用
  9. 图解RGB565、RGB555、RGB16、RGB24、RGB3
  10. android中自定义SeekBar