Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps setMap() and map options

I am new to Google maps api v3. In the Google maps official tutorial, some of the sample code using

new google.maps.Marker({
 map: map    //Map option
});

or

new google.maps.Marker({
 //some options here
}).setMap(map);

What are the difference between each other?

like image 240
vzhen Avatar asked Mar 23 '26 08:03

vzhen


1 Answers

Off the top of head:

  1. You can create markers and add them to a map at a later time e.g. after clicking some button using setMap()
  2. You can have multiple maps on one page. You can selectively add markers to any one of them using setMap()
  3. You can also remove markers selectively from a map using setMap(null)
like image 152
Salman Avatar answered Mar 26 '26 13:03

Salman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!