Berry, I'd like to resurrect this thread as it turned out I have a weird issue that you (or somebody else) may help with. As we discussed in this thread, it's possible to replace fromLatLngToPixel() with a formula to calculate pixel position. For some reason, this calculation is *sometimes* one pixel off from what's calculated by fromLatLngToPixel().
Here is the map: http://notebook.kulchenko.com/maps/gridapi When it's loaded you'll see: 198329=198330; 420541=420541 The first number is X coordinate as calculated by the algorithms we discussed in this thread; the second one is as calculated by fromLatLngToPixel(). When you move the map a bit to the right (to see the tile boundary) you'll notice that there is indeed one pixel difference. I *never* saw this problem with Y values. Even X values are correct most of the time, but sometimes they are off by one pixel. Here is the formula: var OFFSET = 268435456; var LngToX = function (lng) { return ~~(0.5 + OFFSET + lng*OFFSET/ 180); } var x = LngToX(center.lng()) >> (21 - zoom); I also checked using your exact formula and got the same result. There is one more thing I can't explain: when I compare tile offset (as generated by google) with the offset I calculate in v3, I'm always off by one pixel. In v2 I only occasionally off; most of the time it's correct. Any ideas about what may be going on? Paul (http://notebook.kulchenko.com/maps) On Sep 15, 5:45 am, bratliff <[email protected]> wrote: > On Sep 15, 7:29 am, Paul Kulchenko <[email protected]> wrote: > > > I also switched to using my own calculations for the Mercator > > projection and it seems to be almost 5 times faster than gmap's > > fromLatLngToPixel(). I didn't expect such a significant difference (on > > 1000+ points). Although there may be other factors in play that I > > haven't excluded (I haven't tried the simplest possible example just > > to benchmark it). > > Yep. Virtually all Google maps are Mercator but "fromLatLngToPixel()" > has to be able to handle other oddball projections. It also requires > a "new GLatLng()" object for every call which just adds overhead. V3 > does not even provide a "fromLatLngToPixel()" method. V3 does provide > a "fromLatLngToDivPixel()" method but for tile numbers, you must roll > your own. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" 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-api?hl=en -~----------~----~----~----~------~----~------~--~---
