I want to identify the coordinates by tapping a point on the map.Here is my code snippet.
mMapView.setOnSingleTapListener(new OnSingleTapListener() {
private static final long serialVersionUID = 1L;
public void onSingleTap(float screenX, float screenY) {
mLocationLayer2.removeAll();
Point mapPoint = mMapView.toMapPoint(screenX, screenY);
// Point pnt = (Point) GeometryEngine.project(mapPoint, mMapView.getSpatialReference(), SpatialReference.create(4326));
SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.YELLOW,15, SimpleMarkerSymbol.STYLE.X);
TextSymbol txtSym = new TextSymbol(20, String.valueOf(mapPoint), Color.RED);
txtSym.setOffsetX(10);
txtSym.setOffsetX(10);
Graphic gMarker = new Graphic(mapPoint, sms);
Graphic gText = new Graphic(mapPoint, txtSym);
mLocationLayer2.addGraphics(new Graphic[] { gMarker, gText });
}
});
Here when tapped on the map, appears a text symbol with "Point[m_attributes[8966832.811,663665.135],m_description=com.esri.geometry.VertexDescription@7c5d0f85]"
But only i want to appear coordinates on the map. So how can i do that?
Please help me on this.. Thank you
Solved! Go to Solution.
Ah. It looks like you're getting the toString() representation of the Point geometry as your label text.
" TextSymbol txtSym = new TextSymbol(20, String.valueOf(mapPoint), Color.RED);"
You can explicitly construct the text for the label from getting the X and Y attributes of the Point geometry itself.
For example, do something like:
String labelText = mapPoint.getX() + " , " + mapPoint.getY();
Then:
"TextSymbol txtSym = new TextSymbol(20, labelText, Color.RED);"
See what I mean?
Hope this helps.
Are you saying that your text graphic is not showing up on the Map?
Thank you for the reply..No.. that's show on the map. I only want to show coordinates of the tapped point. But here shows unnecessary things.
Here is the text that shows on text graphic: "Point[m_attributes[8966832.811,663665.135],m_description=com.esri.geometry.VertexDescription@7c5d0f85]"
But i only want to see 8966832.811, 663665.135 on the text graphic.
Hello... i'm waiting for the answer
Ah. It looks like you're getting the toString() representation of the Point geometry as your label text.
" TextSymbol txtSym = new TextSymbol(20, String.valueOf(mapPoint), Color.RED);"
You can explicitly construct the text for the label from getting the X and Y attributes of the Point geometry itself.
For example, do something like:
String labelText = mapPoint.getX() + " , " + mapPoint.getY();
Then:
"TextSymbol txtSym = new TextSymbol(20, labelText, Color.RED);"
See what I mean?
Hope this helps.
Thank you soo much..