Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google places API icons

I'm working with Google's Places API (http://code.google.com/apis/maps/documentation/places/). I'd like to use the icons that Google passes as part of the places result set, but they look huge and out of scale.

According to Google's docs on the Marker object, the Marker.setIcon method should auto scale the image to fit the map.

I'm using something like this:

var marker      = new google.maps.Marker({
                                      map: map,
                                      position: place.geometry.location
                 });
marker.setIcon(place.icon);

and it works, but the image isn't scaling. It appears to be about ~75px square no matter what. I have also tried writing this image into a new MarkerImage object which I could then scale, but this seems pretty over complicated.

Is there a trick to getting the icon image to scale properly?

like image 625
julio Avatar asked Dec 16 '22 09:12

julio


1 Answers

Ok I didn't get any ideas here, so I went ahead and created a new MarkerImage object and scaled that. Works fine, not quite elegant, but here it is:

// pass in the place object returned by the Google Place API query
function createPlace(place){
  var gpmarker    = new google.maps.MarkerImage(place.icon, null, null, null, new google.maps.Size(25, 25));
  var marker      = new google.maps.Marker({
    map: map,
    position: place.geometry.location,
    title: place.name,
    icon: gpmarker
  });
}
                    }
like image 166
julio Avatar answered Jan 08 '23 08:01

julio