开发者

Display error using google maps tile server and Google Maps utility in PHP

I have a question regarding Map tile server and coordinates conversion in Google Maps using the Google Maps Utility library.

My tile server accesses a database with thousands of gps coordinates (lat,lng), and for every (lat,lng) point, checks if the point is inside the geographical bounds of the tile; if it does, coordinates conversion (WGS84 -> Mercator -> X,Y offset inside the tile) and paints the corresponding pixel inside the tile, using the GoogleMapsUtility Library.

In terms of code, I do the following:

$point = GoogleMapUtility::getOffsetPixelCoords((float)$row['lat'], (float)$row['lng'], $zoom, $X, $Y);

which calls the getOffsetPixelCoords function (and in turn the functions below) from the library:

public static function getOffsetPixelCoords($lat,$lng,$zoom, $X, $Y) 
    {
        $pixelCoords 开发者_如何学Go= GoogleMapUtility::getPixelCoords($lat, $lng, $zoom);
        return new Point(
            $pixelCoords->x - $X * GoogleMapUtility::TILE_SIZE, 
            $pixelCoords->y - $Y * GoogleMapUtility::TILE_SIZE
        );
    }


public static function getPixelCoords($lat, $lng, $zoom) 
    {
        $normalised = GoogleMapUtility::_toNormalisedMercatorCoords(GoogleMapUtility::_toMercatorCoords($lat, $lng));
        $scale = (1 << ($zoom)) * GoogleMapUtility::TILE_SIZE;
        return new Point(
            (int)($normalised->x * $scale), 
            (int)($normalised->y * $scale)
        );
    }

private static function _toNormalisedMercatorCoords($point) 
    {
        $point->x += 0.5;
        $point->y = abs($point->y-0.5);
        return $point;
    }

Ok, now the results. For a zoom level<13 it works great, below is an example of a tile in Zoom level 11:

Image1

However, for a tile in zoom level >13, the following happens:

Image2

Which is so strange... the pixels seem to be perfectly aligned ? At first I thought it is a decimal resolution problem, but the resolution of the data is quite good (stored as double in a mysql database, for example, 35.6185989379883, 139.731994628906, and in php floats and doubles are the same thing...)

Could someone help me on how to fix this problem?

Thanks in advance...


Why do you use type casting on the result of the database query? In the example of the book googlemapsutility it's not there?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜