2

I want to use geocode in our application. so that, I got Google geocoding API and could achieve with Google Maps. Problem is that I wanted to achieve the same with my own map which is having projection EPSG:4326 INSTEAD OF getting geocoded from Google Map which is having projection EPSG:3857. or I am getting a coordinates from Google geocoding projection EPSG:3857 and that coordinates I want to mark on my OpenLayers Map which is having projection EPSG:4326

please help me.

2 Answers 2

6

The following piece of code allows you to transform your latitude and longitude coordinates from epsg:3857 to epsg:4326 in just one line. Just substitute longitude and latitudine values to LON and LAT in the code.

point = new OpenLayers.LonLat(LON,LAT).transform('EPSG:4326', 'EPSG:3857');

In point you'll have an OpenLayers readable point.

2
  • 1
    Your Answer was flagged up as low-quality because of its length. I recommend that you add a paragraph to give more context about how it addresses the Question.
    – PolyGeo
    Commented Jan 2, 2014 at 22:07
  • 1
    Ya, I'm sorry, didn't have so much time yeasterday :)
    – Alberto
    Commented Jan 3, 2014 at 8:29
2

Asuming you have the latitude and Longitude in the appropriate variables, you can use the following code to project the point:

var epsg4326 = new OpenLayers.Projection('EPSG:4326');
var epsgWebMercator = new OpenLayers.Projection('EPSG:3857');
var pt_latLong=new OpenLayers.Geometry.Point(lon, lat);
var pt_webMercator= pt_latLong.transform(epsg4326,epsgWebMercator);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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