On Feb 7, 4:59 pm, Martin Matysiak <[email protected]> wrote:
> I'm not absolutely sure if I've understood your problem, so here's what I
> think you want to do:
>
> You have an marker-icon that is shifted some pixels (!) away from the actual
> location you want to point at. When the user clicks on the marker, a line
> from your anchor to the actual location shall be drawn. Is this correct?
>
> If this would be the case, I have implemented the following method:
>
> /*
>  * Calculates the Latitude/Longitude per
>  * Pixel ratio based on the given zoom.
>  *
>  * If you want to speed up things, you might
>  * replace the formula by an array of constant
>  * LatLng values, as the ratio isn't depending
>  * on any factors but the map's scaling. If
>  * This should change in the future, you would have
>  * to adjust the formula either way.
>  *
>  * @param zoom The zoom value for which you want
>  *          to know the conversion ratio from
>  *          pixel to LatLng
>  */
> function getLatLngPerPixel(zoom) {
>         var lng = 360 / (256 * (Math.pow(2,zoom))); //256 is the Map Width 
> (px) on zoom = 0
>         var lat = 2 * lng / Math.PI;
>
>         return new google.maps.LatLng(lat, lng);
>
> }
>
> This method gives you the "size" of a pixel in Latitude/Longitude
> coordinates for a specific map zoom (by the way, you could also fill this
> method with a static array containing the precalculated values for each
> zoom). Now if you want to draw a line from your location to the anchor, just
> get the conversion ratio, take your location as point A of the line, then
> calculate point B of the line by multiplying your x/y values with the
> corresponding conversion ratio and adding this to the coordinates of your
> point A.

Unfortunately,  LngToX & XToLng are linear but LatToY & YToLat are non
linear.  Using a constant multiplier for the vertical component will
not work.  It is the reason Google has to chop flat images into
horizontal slices to force a Euclidian projection to look like a
Mercator projection.  At very deep zoom levels, you may not notice it.

Several different versions of the conversion functions are floating
around.  See:

    http://www.polylib.us/adjust.js

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to