OS Maps is a product of Ordnance Survey, the national mapping agency for Great Britain. They provide an API which allows to request detailed map tiles based on zoom level and tile coordinates.

Google maps is …. I think there is no need to describe Google Maps!

As OS Maps are more detailed than Google Maps it might be useful to display OS Maps tiles over Google Maps. And the problem is how to combine tile indeces with latitude/longitude coordinates.

OS Maps uses a variation of Universal Transverse Mercator coordinate system and each zoom level has its own set of tiles.

To convert spherical coordinates to Mercator we can use the following function (written in php):

function ($lat, $lng, $zoom) {
    $scale = 1 << $zoom;
    $siny = sin($lat * pi() / 180);

    // Truncating to 0.9999 effectively limits latitude to 89.189. This is
    // about a third of a tile past the edge of the world tile.
    $siny = min(max($siny, -0.9999), 0.9999);

    return [
      floor($scale * (0.5 + $lng / 360)),
      floor($scale * (0.5 - log((1 + $siny) / (1 - $siny)) / (4 * pi())))
    ];
}

Then you can use the result of this function to request OS Maps tile which contains specified lat/lng location. For example:

https://api2.ordnancesurvey.co.uk/mapping_api/v1/service/zxy/EPSG:3857/Outdoor%203857/{ZOOM}/{X}/{Y}.png?key={KEY}

where {X} and {Y} are retrieved from the function above.

Are you interested in integrating Google and OS Maps?
We already have such experience and we are ready to help!

Request a quote

Related Post

Post Not Found.