apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Getting blank map when no markers defined #481

Open genlighten opened 9 years ago

genlighten commented 9 years ago

I use gmaps on our site to display where our service providers are located in a given city, state or country. Sometimes users will search for an area where we don't have any service providers yet. In that case, I still want to display a properly-zoomed map of the respective location. When I have no markers to pass to handler.bounds.extendWith(markers), how can I set the lat/lon centroid and zoom level so I don't get a blank map?

apneadiving commented 9 years ago

look at the js code in this plnkr: http://plnkr.co/edit/VvAUnf2uMv38EpjXiBl7?p=preview

  if (_.isEmpty(markers)){
    handler.getMap().setZoom(12);
    handler.getMap().setCenter({lat: -34, lng: 151});
  }
  else{
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds();        
  }