Using fromLatLngToDivPixel in v3

3,003 views
Skip to first unread message

Thai Dang Vu

unread,
Mar 1, 2010, 11:31:37 AM3/1/10
to google-map...@googlegroups.com
Hi Everybody,

I looked at the v3 API reference and noticed that if I want to use methods like fromLatLngToDivPixel ... I need a MapCanvasProjection object. And to have a MapCanvasProjection object, I need an OverlayView object.

In my situation, I don't have any overlay on the map. For example, I show the road map at some (lat, lng) and at some zoom level. Now I need to know the pixel position when the user clicks on the map. To do that in v2, I listen to the map click event where I have the (lat, lng) and use map.fromLatLngToDivPixel. In v3, the object map doesn't have that method. How I can do the same thing in v3?

Thank you.

Marcelo

unread,
Mar 1, 2010, 12:39:42 PM3/1/10
to Google Maps JavaScript API v3
On Mar 1, 5:31 pm, Thai Dang Vu <tdan...@gmail.com> wrote:
> I looked at the v3 API reference and noticed that if I want to use methods
> like fromLatLngToDivPixel ... I need a MapCanvasProjection object. And to
> have a MapCanvasProjection object, I need an OverlayView object.

Look at this example:
http://code.google.com/apis/maps/documentation/v3/examples/map-coordinates.html
It contains a MercatorProjection object.

... and the explanation of how things work in V3:
http://code.google.com/apis/maps/documentation/v3/overlays.html#CustomMapTypes
Pay special attention to "World Coordinates".

--
Marcelo - http://maps.forum.nu
--

helen

unread,
Apr 15, 2010, 5:38:02 PM4/15/10
to Google Maps JavaScript API v3
Hi,
I think I am looking for the same information but the links above did
not completely answer it for me. I need to get the pixel co-ordinates
of a point within my map div and I am having trouble figuring it out
from the world co-ordinates. If I mulitply them by 2 to the power of
zoom as described in the link above, I get the number of pixels from
0,0 on the whole map, not the current view (i.e. div container). Is
there a straightforward method to get this information? I can't seem
to figure it out.
Thanks.

On Mar 1, 1:39 pm, Marcelo <marcelo...@hotmail.com> wrote:
> On Mar 1, 5:31 pm, Thai Dang Vu <tdan...@gmail.com> wrote:
>
> > I looked at the v3 API reference and noticed that if I want to use methods
> > like fromLatLngToDivPixel ... I need a MapCanvasProjection object. And to
> > have a MapCanvasProjection object, I need an OverlayView object.
>

> Look at this example:http://code.google.com/apis/maps/documentation/v3/examples/map-coordi...


> It contains a MercatorProjection object.
>

> ... and the explanation of how things work in V3:http://code.google.com/apis/maps/documentation/v3/overlays.html#Custo...


> Pay special attention to "World Coordinates".
>
> --

> Marcelo -http://maps.forum.nu

William

unread,
Apr 16, 2010, 1:44:02 AM4/16/10
to Google Maps JavaScript API v3
the OverlayView has a MapCanvasProjection, which has the
fromLatLngToDivPixel method:

http://code.google.com/intl/nl/apis/maps/documentation/v3/reference.html#MapCanvasProjection

a way to get coordinates is to create an empty OverlayView and set the
map. This will link the map div to the overlay.

click on the map to see coordinates:
http://www.william-map.com/20100416/1/map.htm


...

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

helen

unread,
Apr 16, 2010, 11:14:41 AM4/16/10
to Google Maps JavaScript API v3
That works, thanks!
I could not glean that from the documentation. Maybe my head is a
little stuck in v2, or it needs more explanation somewhere (or both!)

On Apr 16, 1:44 am, William <william.g...@gmail.com> wrote:
> the OverlayView has a MapCanvasProjection, which has the
> fromLatLngToDivPixel method:
>
> http://code.google.com/intl/nl/apis/maps/documentation/v3/reference.h...
Reply all
Reply to author
Forward
0 new messages