Add simple marker to arcgis map

1122
2
Jump to solution
02-01-2021 04:52 AM
RahulFernando
New Contributor

I'm try to add simple markers to my map I have followed the documentation, it worked. But I change the location map doesn't appear properly, it like zoomed. What I am missing here. 

 

 

private MapView mapView;
private GraphicsOverlay graphicsOverlay;
private SimpleMarkerSymbol node;
private Point graphicPoint;
Graphic graphic;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  mapView = (MapView) findViewById(R.id.mapView);

  ArcGISMap arcGISMap = new ArcGISMap(Basemap.Type.IMAGERY,6.91621555958787, 79.97325625691973, 12);
  mapView.setMap(arcGISMap);
  mapView.setViewpoint(new Viewpoint(new Point(6.91621555958787, 79.97325625691973, SpatialReferences.getWebMercator()), 7500));

  graphicsOverlay = new GraphicsOverlay();
  mapView.getGraphicsOverlays().add(graphicsOverlay);

  node = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
  graphicPoint = new Point(6.91621555958787, 79.97325625691973, SpatialReferences.getWebMercator());
  graphic = new Graphic(graphicPoint, node);
  graphicsOverlay.getGraphics().add(graphic);

}

 

 

 

0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

I can see the issue here.  The point you are creating is in the wrong spatial reference.  This is how you should be creating the point I believe you want which is a latitude and longitude.

 

 

 

 

graphicPoint = new Point(79.97325625691973,6.91621555958787, SpatialReferences.getWgs84());

 

 

 

 

You were centring your map based on a latitude and longitude which are angles measures from the centre of the earth in angles of degrees.  This is what we call a geographic projection and in this case is called WGS84.  Note that in navigation people say latitude then longitude, but in mathematics we say x then y, which of course causes confusion!  Note the order of coordinates changed when I specified the point.

The coordinate system you were using was a projected coordinate system of which there are lots, but this is a global one called Web Mercator covering rather crudely the entire Earth and not being particularly good good for mapping the North or South Poles!  The units of measure here are in metres and measured from an origin which sits in the sea just off the West coast of Africa - very near to where you were placing your point by accident.

If you are interested in more details you could read this: https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/coordinate-systems-difference/#:~:text=....

 

Also you've got the same issue when setting the ViewPoint.  This code should help:

 

 

mapView.setViewpoint(new Viewpoint(new Point(79.97325625691973,6.91621555958787, SpatialReferences.getWgs84()), 7500));

 

 

Does this help?

 

View solution in original post

0 Kudos
2 Replies
MarkBaird
Esri Regular Contributor

I can see the issue here.  The point you are creating is in the wrong spatial reference.  This is how you should be creating the point I believe you want which is a latitude and longitude.

 

 

 

 

graphicPoint = new Point(79.97325625691973,6.91621555958787, SpatialReferences.getWgs84());

 

 

 

 

You were centring your map based on a latitude and longitude which are angles measures from the centre of the earth in angles of degrees.  This is what we call a geographic projection and in this case is called WGS84.  Note that in navigation people say latitude then longitude, but in mathematics we say x then y, which of course causes confusion!  Note the order of coordinates changed when I specified the point.

The coordinate system you were using was a projected coordinate system of which there are lots, but this is a global one called Web Mercator covering rather crudely the entire Earth and not being particularly good good for mapping the North or South Poles!  The units of measure here are in metres and measured from an origin which sits in the sea just off the West coast of Africa - very near to where you were placing your point by accident.

If you are interested in more details you could read this: https://www.esri.com/arcgis-blog/products/arcgis-pro/mapping/coordinate-systems-difference/#:~:text=....

 

Also you've got the same issue when setting the ViewPoint.  This code should help:

 

 

mapView.setViewpoint(new Viewpoint(new Point(79.97325625691973,6.91621555958787, SpatialReferences.getWgs84()), 7500));

 

 

Does this help?

 

0 Kudos
RahulFernando
New Contributor

Thank you very much

0 Kudos