wildnove
wildnove

Reputation: 2305

How to convert an Android esri arcGIS Point into latitude and longitude

I'm trying to get Latitude and Longitude of a tap over a Android esri arcGIS MapView.

        map.setOnSingleTapListener(new OnSingleTapListener() {

            private static final long serialVersionUID = 1L;

            public void onSingleTap(float x, float y) {
                System.out.println("x:" + x);
                System.out.println("y:" + y);
                // How to get Latitude Longitude coordinates of the point (x,y)?

            }
        });

How to get Latitude Longitude coordinates of the point (x,y)?

Upvotes: 1

Views: 3410

Answers (4)

Luther
Luther

Reputation: 625

I tired this Solution in kotlin and its working as expected

       val sp = SpatialReference.create(4326)
       // where Location is the Point
       val locationPoint = GeometryEngine.project(location, sp) as Point
       val lat = locationPoint.x
       val lng = locationPoint.y

Upvotes: 1

kiran
kiran

Reputation: 3264

map.setOnSingleTapListener(new OnSingleTapListener() {

            private static final long serialVersionUID = 1L;

            public void onSingleTap(float x, float y) {
                System.out.println("x:" + x);
                System.out.println("y:" + y);


Point p=map.toMapPoint(x,y );

 SpatialReference sp = SpatialReference.create(/*spatial number*/);
 Point aux = (Point) GeometryEngine.project(p, map.getSpatialReference(), sp);

System.out.println("latitude="+aux.getX());
System.out.println("longitude="+aux.getY());

            }
        });

for spatial number spatialreference.org

Upvotes: 0

yash
yash

Reputation: 397

If you want to convert map point to lat/long you just need to follow this

Point mapPoint = mMapView.toMapPoint(point.getX(), point.getY());
//Here point is your MotionEvent point
SpatialReference spacRef = SpatialReference.create(4326);
//4326 is for Geographic coordinate systems (GCSs) 
Point ltLn = (Point)
GeometryEngine.project(mapPoint,mMapView.getSpatialReference(), spacRef ); 
//mMapView is your current mapview object

ltLn.getY() will give latitude and ltLn.getX() will give longitude

Upvotes: 1

Manuel Pires
Manuel Pires

Reputation: 637

The easiest way is:

Point p=map.toMapPoint(arg0, arg1);
System.out.println("X="+p.getX());
System.out.println("Y="+p.getY());

The variable p will have the coordinates mapped in the MapView.

Upvotes: 3

Related Questions