正确更改Google Maps V3 Maker图标吗? [英] Changing Google Maps V3 Maker Icon the correct way?

查看:60
本文介绍了正确更改Google Maps V3 Maker图标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例1中的代码有效.我想了解marker.setIcon();功能更多(JavaScript也是新功能).

The code in example 1 works. I would like to understand the marker.setIcon(); function more (new to JavaScript also).

我的问题是.在Google地图文档中,您会看到类似的更改标记的信息.

My question is. In the documentation for Google maps you see something like this for changing the marker.

MarkerImage(url:string, size?:Size, origin?:Point, anchor?:Point, scaledSize?:Size)

这与我在示例1中为设置标记Icon所做的工作有什么关系,应该代替吗?

How does this relate to what I have done in example 1 for setting up marker Icon, shoud I have done somethign like this instead?

marker = google.maps.MarkerImage({
        url: "newIcon.png"
});

marker.setIcon(marker);

那行得通吗?

这是我的例子

示例1

function initialize(){
//MAP

  var latlng = new google.maps.LatLng('xxx','xxx');
  var options = {
    zoom: 16,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };

  map = new google.maps.Map(document.getElementById("map_canvas"), options);

  //GEOCODER
  geocoder = new google.maps.Geocoder();

  marker = new google.maps.Marker({
    map: map,
    draggable: true
  });     

  marker.setPosition(latlng);
  marker.setIcon("newIcon.png");
  map.setCenter(latlng);

}

推荐答案

您要为V3问题提供V2答案.

You're giving a V2 answer for a V3 question.

V3中没有GIcon.

There is no GIcon in V3.

var image = new google.maps.MarkerImage("newIcon.png");

可以在标记内用作图标.

Can be used inside your marker as the icon.

var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat,lng),
        icon:image
    });

这篇关于正确更改Google Maps V3 Maker图标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆