简体   繁体   中英

specify size of custom marker in google map

I am trying to put custom markers on a google map. The icons that I want to use are png files and vary based on the type of point being placed on the map. Both the location of the point and the url of the png file for its marker are being pulled from an SQLdatabase.

The code I am using is as follows

var mapOptions = {
    center: new google.maps.LatLng(markers[0].lat, markers[0].lon),
    zoom: 7,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    //  marker:true
};
var infoWindow = new google.maps.InfoWindow();

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
for (i = 0; i < markers.length; i++) {
    var data = markers[i]
    var myLatlng = new google.maps.LatLng(data.lat, data.lon);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: data.venue,
        icon: data.image
    });

When this is run, I get very large markers on my map, each marker is the correct one, but they are so large that it looks like a jumble.

Any suggestions on how to control the size of the icon?

You could specify a google.maps.Icon as the MarkerOptions, eg

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: data.venue,
    icon: {
        url: data.image,
        scaledSize: new google.maps.Size(32, 32)
    }
});

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