Problem regarding search coordinates on the map

3949
5
Jump to solution
04-05-2015 12:10 AM
thilibu
New Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
EricBader
Occasional Contributor III

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.

View solution in original post

5 Replies
EricBader
Occasional Contributor III

Are you saying that your text graphic is not showing up on the Map?

0 Kudos
thilibu
New Contributor II

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.

0 Kudos
thilibu
New Contributor II

Hello... i'm waiting for the answer

0 Kudos
EricBader
Occasional Contributor III

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.

thilibu
New Contributor II

Thank you soo much..

0 Kudos