Select to view content in your preferred language

How to get center of the mobile screen Coordinates

1789
1
04-28-2021 10:24 PM
TrilokChouhan
Emerging Contributor

We are developing one mobile application where we need centre of the mobile screen coordinates. We explored the complete SDK library but couldn’t find right API to get the centre of mobile screen coordinates.

 

Although we have written our custom code to get the centre coordinates but facing issue as the centre coordinates accuracy is dependent on the zoom level (Higher zoom: higher accuracy).  Custom code is given below:

 

=============================

val centreX = mapView.x + mapView.width / 2

val centreY = mapView.y + mapView.height / 2

val screenPoint1 = android.graphics.Point(

    Math.round(centreX),

    Math.round(centreY)

)

mapPoint1 = mapView.screenToLocation(screenPoint1)

destination = GeometryEngine.project(

        mapPoint1,

        SpatialReferences.getWgs84()

)

Log.e(

        "PointCollection Value",

        "---Coordinates---" + startPoint!!.y + "--lng" + startPoint!!.x

)

=======================================

 

Please suggest the solution...

1 Reply
RamaChintapalli
Esri Contributor

Hi,

You can get map Center Point as below,

mMapView.getVisibleArea().getExtent().getCenter()

 

If  you need screen coordinates, you can use mMapView.locationToScreen(mapCenterPoint)

Thanks
Rama