Unable to map my latitude and longitude to correct location

1665
5
Jump to solution
11-04-2019 11:52 PM
AhsanApp
New Contributor III

Hello team esri.

I am using arcgis-runtime library 100.4.0 on android and I have tried several ways to map my marker on the points.

Point point = (Point) GeometryEngine.project(new Point(x, y), SpatialReference.create(102739));
Point point = new Point(x, y, SpatialReference.create(102739));
Point point = new Point(x, y);
and finally I am doing this:
graphicsOverlay.getGraphics().add(graphic);
graphicIds.add(position);

The value I am getting from point = Point: [38.915019, -77.009938, 0.000000, NaN] SR: 102739

but all are pointing to invalid coordinates.

Testing on device Samsung S9. Target sdk 28 and min sdk 24.

Thanks.
0 Kudos
1 Solution

Accepted Solutions
AhsanApp
New Contributor III

Thanks Colin, I used the graphic constructor to pin the location so it looks like this now.

Graphic graphic = new Graphic(x, y);
graphic.setSymbol(pictureMarkerSymbol);
graphic.getAttributes().putAll(attr);

Working as expected.

View solution in original post

0 Kudos
5 Replies
ColinAnderson1
Esri Contributor

You can use the following constructor on Graphic to directly create a graphic from lat/lon values and once it is added to a graphics overlay it should display correctly in the overlay's coordinate system.

  /**    
  * Creates a new graphic with a point defined in the WGS 84 SpatialReference.    
  *    
  * @param latitude the latitude    
  * @param longitude the longitude    
  * @since 100.0.0    
*/   
public Graphic(double latitude, double longitude)

To reproject the point directly I think you need something like

Point point = (Point) GeometryEngine.project(new Point(x, y, SpatialReferences.WGS84), SpatialReference.create(102739));

so that the original project of the point is also defined as well as the target projection.

0 Kudos
AhsanApp
New Contributor III

Thanks Colin, I used the graphic constructor to pin the location so it looks like this now.

Graphic graphic = new Graphic(x, y);
graphic.setSymbol(pictureMarkerSymbol);
graphic.getAttributes().putAll(attr);

Working as expected.

0 Kudos
by Anonymous User
Not applicable

Hi Ahsan,

Can you share a bit more of your code? Just want to make sure I'm not misunderstanding what you're doing in the code above. Just have a few questions:

1) Those are three different points you're making in your code, you're definitely assigning them to them as the geometry to your graphic?

2) I can see the Spatial Reference (wkid-well known id) is for a very specialized coordinate system for a local coordinate system in Texas, but the x y values you give look like you're trying to use WGS84 to put a marker in the Washington DC area. Are you sure you don't mean to be using `SpatialReferences.getWgs84()`?

3) What makes it invalid? Is it not drawing where you expect or are you getting an error of some kind?

Thanks!

Trevor

0 Kudos
AhsanApp
New Contributor III

Hi Trevor.

Below is the complete code I am using to display the marker.

Point point = new Point(x, y, SpatialReference.create(102739));
//point = new Point(x,y);
Map<String, Object> attr = new HashMap<>();
attr.put("position", position);
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol((BitmapDrawable) getResources().getDrawable(R.mipmap.pin_blue));
Graphic graphic = new Graphic(point, attr, pictureMarkerSymbol);
//graphic.computeCalloutLocation(point, mMapView);
graphicsOverlay.getGraphics().add(graphic);
graphicIds.add(graphicsOverlay.getGraphics().get(graphicsOverlay.getGraphics().size() - 1).getZIndex());

I hope this answers your first question.

Yes, I am targeting the Washington DC area, so I will be changing my Spatial Reference to Wgs84.

By invalid I mean the markers are not placed on the expected location.

Thanks.

0 Kudos
by Anonymous User
Not applicable

Ok, let me know how you get on with Wgs84.

Also, this sample is doing most of the things you're trying to do (creating a graphic from a point and a picture marker symbol). Could be a helpful reference.

Cheers,

Trevor