ol2 icon indicating copy to clipboard operation
ol2 copied to clipboard

Google Hybrid Map tiles won't load in OpenLayers when centered on certain position

Open mickel1138 opened this issue 10 years ago • 6 comments

Since the Google Maps API update to V3.19 (also doesn't work in V3.20) our maps have not been loading to their initial state, centered over the Gulf of Mexico.

When the center location is: center: new OpenLayers.LonLat(-90, 25) it doesn't render, but OpenLayers.LonLat(-91, 25) works fine. Any 90 lon or 0 lat fails.

Example: var map;

$(document).ready(function () {
    map = new OpenLayers.Map('olmap', {
        projection: 'EPSG:3857',
        layers: [
        new OpenLayers.Layer.Google(
            "Google Hybrid", {
            type: google.maps.MapTypeId.HYBRID,
            numZoomLevels: 20
        })],
        center: new OpenLayers.LonLat(-90, 25) //change to -91 and it works.
            .transform('EPSG:4326', 'EPSG:3857'),
        zoom: 4
    });
});
See http://jsfiddle.net/mickel1138/cuz00fg9/ for your experimenting pleasure.

mickel1138 avatar Feb 19 '15 16:02 mickel1138

A latitude of -90 cannot be transformed to Web Mercator, because that lies in I finite space. For Web Mercator, you cannot use latitudes beyond 85 or 86 degrees reliably.

Closing because this is an application/configuration issue. If this configuration worked in the past, it worked by chance only.

ahocevar avatar Feb 19 '15 22:02 ahocevar

Also note that OpenLayers.LonLat takes the longitude as first and the latitude as 2nd argument.

ahocevar avatar Feb 19 '15 22:02 ahocevar

I agree that a latitude of near 90 can be problematic, but the latitude in the example is 25, and the longitude is 90.

mickel1138 avatar Feb 19 '15 22:02 mickel1138

Reopening. You wrote latitude of 90, but meant longitude.

If you can provide a pull request with a fix, we'll gladly merge. But supporting the ever changing Google Maps API has been a pain so it's very unlikely that this will be fixed by one of the core devs.

ahocevar avatar Feb 19 '15 22:02 ahocevar

Sorry, yes, I mixed them up earlier (corrected now) although, the example was correct.

mickel1138 avatar Feb 19 '15 22:02 mickel1138

I do believe this is a major bug, using 0 or 90 for either lon or lat causes the map not to render. Moving the map will make it render however.

mickel1138 avatar Feb 19 '15 22:02 mickel1138