1

Could you please help me to convert OpenLayers (srid 3943) extend to Google bounds. I want to geocode from address in my map area so I do this:

var googleProjection = new OpenLayers.Projection("EPSG:900913");
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("geocodeAddress").value;
popupGeo.destroy();

var northEast = new OpenLayers.LonLat(map.maxExtent.right,map.maxExtent.top);
var southWest = new OpenLayers.LonLat(map.maxExtent.left, map.maxExtent.bottom);
var convertedNorthEast = new northEast.transform(map.getProjectionObject(), googleProjection);
var convertedSouthWest = new southWest.transform(map.getProjectionObject(), googleProjection);
var googleBounds = new google.maps.LatLngBounds(convertedSouthWest, convertedNorthEast);

//var convertedBounds = map.maxExtent.transform(map.getProjectionObject(), googleProjection);
//var googleBounds = new google.maps.LatLngBounds(
//    new google.maps.LatLng(convertedBounds.bottom, convertedBounds.left),
//    new google.maps.LatLng(convertedBounds.top, convertedBounds.right));//, 'bounds': googleBounds

geocoder.geocode({ 'address': address }, function (results, status) {

    if (status == google.maps.GeocoderStatus.OK) {

        var newCenter4326 = new OpenLayers.LonLat(results[0].geometry.location.lng(), results[0].geometry.location.lat());
        var newCenter = newCenter4326.transform(googleProjection, map.getProjectionObject());

        map.setCenter(newCenter, GPSLocationZoomLevel);

    } else {
        alert("Impossible de déterminer la position : " + status);
    }
});

but I get an error Phi2z no convergence when I try to convert OpenLayers corners to Google epsg4326

  • Google uses 3857 (once known as 900913). – John Powell Mar 26 '15 at 17:50
  • i also try 900913 but it didn't work i have an error when i try to convert from 3943 to 4326. – JD11 Mar 26 '15 at 17:54
  • i update my code to be more readable – JD11 Mar 26 '15 at 18:06
1

I use openlayer 2.13 wich doesn't work when trying to transform 3943->4326. If i use directly Proj4js it work fine

   var googleProjection = new OpenLayers.Projection("EPSG:4326");
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("geocodeAddress").value;
popupGeo.destroy();


var northEast = new Proj4js.Point(map.maxExtent.right, map.maxExtent.top);//On appelle la librairie Proj4js qui permet notament des transformations de projection.
var southWest = new Proj4js.Point(map.maxExtent.left, map.maxExtent.bottom);
var source = new Proj4js.Proj('EPSG:3943');//On déclare une projection source
var dest = new Proj4js.Proj('EPSG:4326');//On déclare une projection de destination.

Proj4js.transform(source, dest, northEast);
Proj4js.transform(source, dest, southWest);
var googleBounds = new google.maps.LatLngBounds(new google.maps.LatLng(southWest.y, southWest.x),
                                                new google.maps.LatLng(northEast.y, northEast.x));
0

According to https://developers.google.com/maps/documentation/geocoding/, The bounds parameter defines the latitude/longitude coordinates of the southwest and northeast corners of this bounding box using a pipe (|) character to separate the coordinates.

According to http://dev.openlayers.org/docs/files/OpenLayers/BaseTypes/LonLat-js.html OpenLayers defines OpenLayers.LonLat as a longitude and latitude pair.

Could it be that you need to flip the OpenLayers longitude and latitude pairs to be latitude longitude pairs?

  • convertedNorthEast is not calculated the error was phi2z no convergence. It occur before i use it in google bounds construction – JD11 Mar 26 '15 at 18:04
0

Maybe your EPSG:3943 projection params are wrong: http://spatialreference.org/ref/epsg/3943/

Several other posts referring to you error point out that their projection parameters were wrong: http://lists.osgeo.org/pipermail/geomoose-users/2012-January/003711.html

I've never tried this but it looks like you can define a custom projection in OpenLayers, see this post: http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js

I think you can define a projection in OL like this for EPSG:3943:

Proj4js.defs["EPSG:3943"] = "+proj=lcc +lat_1=42.25 +lat_2=43.75 +lat_0=43 +lon_0=3 +x_0=1700000 +y_0=2200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.