Google Maps marker as a link

后端 未结 2 1736
走了就别回头了
走了就别回头了 2021-02-10 15:10

I am using Google Maps for my website and I wander how can I use the Markers as links? I mean when I click a marker to open a particular link.

Thank you

2条回答
  •  梦如初夏
    2021-02-10 15:36

    That's actually very easy to do. Simply attach an event handler to your marker, and then launch the link by setting window.location.href to your URL. Check out the following examples, which I think should be self explanatory:

    Using the v3 API:

    
     
     
       
      Google Maps Marker as a Link 
      
     
    
      

    Using the V2 API:

    
     
     
         
        Google Maps Marker as a Link 
         
       
       
        

    The above examples will add a marker somewhere in the atlantic ocean. When you click on it, you'll be forwarded to a popular search engine.

提交回复
热议问题