Question

I have an android application that uses arcgis offline map and on the other side I have a bing map. I should send a location to the pc when I just tap on the map. I succeeded to make a pin but I couldn't get how to transform it to a location that is understanded by google maps. I made a toast to present the selected location, my code gives me:

longitude:417
latitude:584

but I should transform it to something like: longitude = 39.54367547 for example. this is my code :

// correcting the location
mMapView.setOnSingleTapListener(new OnSingleTapListener() {
    private static final long serialVersionUID = 1L;

    @Override
    public void onSingleTap(final float x, final float y) {
        if (rd_wrt == 1 || rd_wrt == 2) {
            mapPoint = mMapView.toMapPoint(x, y);
            redPinGraphicalLayer.removeAll();

            Graphic redPinGraphic = new Graphic(mapPoint, redPin);
            redPinGraphicalLayer.addGraphic(redPinGraphic);

            Toast.makeText(getApplicationContext(), "longitude " +x +"\n   latitude " + y,
                    Toast.LENGTH_LONG).show();

            Intent data = new Intent();

            data.putExtra("longitude", longitude);
            data.putExtra("latitude", latitude);
            setResult(RESULT_OK, data);
        }
    }
});
Was it helpful?

Solution

Use GeometryEngine to project mapPoint from map coordinates to geographic coordinates (i.e. longitude and latitude):

Point wgs84Point = (Point) GeometryEngine.project(
        mapPoint,
        mMapView.getSpatialReference(),
        SpatialReference.create(SpatialReference.WKID_WGS84));
longitude = wgs84Point.getX();
latitude = wgs84Point.getY();

If you keep your Toast, you'll want to use longitude and latitude instead of x and y in the Toast string.

UPDATE

If you have x, y, and wkid instead of an ArcGIS Point object, it's easy to create a Point yourself:

Point myPoint = new Point(x, y);
Point wgs84Point = (Point) GeometryEngine.project(
        myPoint,
        SpatialReference.create(wkid),
        SpatialReference.create(SpatialReference.WKID_WGS84));
longitude = wgs84Point.getX();
latitude = wgs84Point.getY();

OTHER TIPS

  • onSingleTap(final float x, final float y): (x,y) is screen coordinate, not map coordinate.
  • mapPoint = mMapView.toMapPoint(x, y): (mapPoint.getX(),mapPoint.getY()) is map coordinate, but it is not (lat,long). you have to use GeometryService to project it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top