Simple Graphic doesn't display on map

985
2
Jump to solution
12-09-2016 03:06 PM
SeanPearson1
New Contributor

I'm using ArcGIS for Android SDK 10.2.8 and trying to place a simple graphic based on current GPS coordinates obtained through Android's location services. I followed the basic guide here:

Add graphics and text—ArcGIS Runtime SDK for Android | ArcGIS for Developers 

I am using ESRI's topo basemap. The map loads as expected and initially centers on the GPS coordinates provided. On pressing a provided button, the map should draw a SimpleMarkerSymbol at the coordinates and re-center the map on the coordinates, if the map has been moved. What actually happens when I press the button is the map will re-center on the coordinates but no graphic appears.

To do a little testing, I tried also displaying a toast with the graphic layer UID. It returns a number, leading me to believe the graphic layer is correctly created....but still no graphic appears on the map. Is there something I am missing in my code? My code for the button is below:

public void setPoint(View view) {
    Button clickedButton = (Button) view;

    if (clickedButton == findViewById(R.id.add_point)) {
        mMapView = (MapView) findViewById(R.id.map);
        SpatialReference webSR = SpatialReference.create(3857);
        Point gps_mercator = GeometryEngine.project(latitude, longitude, webSR);
        GraphicsLayer gl = new GraphicsLayer();
        SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 5, SimpleMarkerSymbol.STYLE.CIRCLE);
        Graphic pointGraphic = new Graphic(gps_mercator, simpleMarker);
        gl.addGraphic(pointGraphic);
        mMapView.addLayer(gl);
        mMapView.centerAt(latitude, longitude, true);
    }
}
0 Kudos
1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

Hi Sean,

There's a difference in the input parameters of MapView.centerAt vs GeometryEngine.project. The project method takes in an x-coordinate and a y-coordinate as parameters; however, centerAt takes in latitude and longitude. Also, note that latitude relates to the y-coordinate (north-south axis), and longitude relates to x-coordinate (east-west axis). This would explain why your centerAt works as you expect but your project does not - you might have a graphic being drawn, but just not where you expect to see it, due to this order of parameters.

When you pass in lat/long values, make sure you pass in the parameters the correct way around - e.g.

Point gps_mercator = GeometryEngine.project(longitude, latitude, webSR);

Hope this helps,

Shelly

View solution in original post

2 Replies
ShellyGill1
Esri Contributor

Hi Sean,

There's a difference in the input parameters of MapView.centerAt vs GeometryEngine.project. The project method takes in an x-coordinate and a y-coordinate as parameters; however, centerAt takes in latitude and longitude. Also, note that latitude relates to the y-coordinate (north-south axis), and longitude relates to x-coordinate (east-west axis). This would explain why your centerAt works as you expect but your project does not - you might have a graphic being drawn, but just not where you expect to see it, due to this order of parameters.

When you pass in lat/long values, make sure you pass in the parameters the correct way around - e.g.

Point gps_mercator = GeometryEngine.project(longitude, latitude, webSR);

Hope this helps,

Shelly

SeanPearson1
New Contributor

This is exactly what I was doing wrong. I reversed the order as indicated in your line of code and it worked! Thank you for the helpful explanation!

0 Kudos