google map api v3: can I use a div instead of an i

2020-04-05 08:25发布

问题:

google map api v3: can I use a div instead of an image to create the custom icon?

i want to be able to hover the marker and change the icon, ven betetr if i could use a fade fx...so how can i set a div instead of an image like it is by default?

回答1:

Yes, You can use Custom Overlays in place of markers:

http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays



回答2:

First, I give the demo-purpose website.

For this question, I have found there are several similar questions which I have already answered such as:

(following one is about theory)

HTML/CSS Markers using Google Maps Javascript API v3

(following one is about implementations)

How to create custom marker for google map

At first answer, I have given my detailed understanding why customized icons and markers should be implemented by extending overlayView class. At second answer, I have posted out how to write HTML/CSS to specify how one customized icon/marker looks. Of course you can also write event handlers to add JS logic to your icon/marker.

At stack overflow, I found several interesting points. When I found similar questions, I cannot answer the question using my previous answer. One content manager even deletes my answer although what I am answering here is exactly the question is asking.

At last, if you need to see how to extend overlayView class to realize one marker, please see this source code (starting below comment //====custom-marker management starts)

Thank you.