frosty
frosty

Reputation: 21762

GoogleMaps: How to add marker without zooming out.

I have a list of people that I need to map. Some of them have geocoded addresses and others don't. So, I map the ones that I have, and then I geocode the ones that I don't have geocodes for, and I add them to the map one at a time. (side note: the google geocoder api has a limiter that allows you geocode 10 addresses the first second that you hit it, and then 1 per second every second after that). So, I as I am geocoding these addresses, I am creating Markers and adding them to the map. The problem here is that I can't effectively interact with the map from the UI while the other addresses are being geocoded, because each time I call marker.setMap(mymap) it re-zooms out to fit all markers. So, I can't interact with the map until they are all mapped. Is there any way to add a marker to the map without re-zooming out?

Upvotes: 0

Views: 157

Answers (1)

Mano Marks
Mano Marks

Reputation: 8819

Geocoding and creating a marker doesn't automatically shift the center of the map. If you copied from the Maps API sample code, you may see a line like

map.setCenter(results[0].geometry.location);

That's causing the results to the center of the map. Comment out that line and see if there's still a problem.If you don't see setCenter, then look for a line with fitBounds() and comment that out. If you're still having trouble, post a live version of your code, or put it up on jsFiddle or something so we can debug it.

Upvotes: 1

Related Questions