简体   繁体   中英

Changing Google Maps V3 Maker Icon the correct way?

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

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)

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

and would that have worked?

here is my example

Example 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);

}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM