Select to view content in your preferred language

Problem regarding search coordinates on the map

4163
5
Jump to solution
04-05-2015 12:10 AM
thilibu
Deactivated User

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
Honored Contributor

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
Honored Contributor

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

0 Kudos
thilibu
Deactivated User

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
Deactivated User

Hello... i'm waiting for the answer

0 Kudos
EricBader
Honored Contributor

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
Deactivated User

Thank you soo much..

0 Kudos