Graphic always shows at mappoint 0,0 while using latitude and longitude

3276
1
05-12-2016 04:20 AM
DeepakBhatia
New Contributor


Hi I am using this code to add a Text SYmbol at given latitude and longitude.(San Francisco)

TextSymbol txtSymbol = new TextSymbol(30, "50", Color.BLUE);

{

     Point mapPoint = ConvertMyLocationPoint(-122.4600595,37.7532508);

     gr = new Graphic((mapPoint), txtSymbol);

     graphicsLayer = new GraphicsLayer();

     //add the graphic to the map
        graphicsLayer.addGraphic(gr);

        mMapView.addLayer(graphicsLayer);

}

private Point ConvertMyLocationPoint(final double longitude, final double latitude) {

  Point wgspoint = new Point(longitude, latitude);

  Point mapPoint = GeometryEngine.project(longitude,latitude,

   mMapView.getSpatialReference());

   return mapPoint;

}

The point always shows up at 0,0(lat, long) in the map.

Is this a wrong way to add point when I have latitude and longitude?

Could anyone suggest how to approach this.

Thanks.

0 Kudos
1 Reply
ShellyGill1
Esri Contributor

Hi Deepak,

I could see anything that looked wrong with your code - I put this into an app, and found the '50' text symbol displays at San Francisco as expected. The ConvertMyLocationPoint function returned a Point like this:

    mapPoint.getX() - -1.3632191466053985E7

    mapPoint.getY() - 4544626.829865076

How is your MapView defined? That's where the coordinate system is being taken from, so I wonder if that is the problem in your case. Here is the MapView definition I was using - as I'm using the Esri basemaps, the spatial reference is Web Mercator Auxiliary Sphere (id = 102100).

<com.esri.android.map.MapView
   android:id="@+id/map"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   mapoptions.MapType="Streets"
   mapoptions.ZoomLevel="1"
   />

What is the Spatial Reference that you're projecting the point to? Does the returned Point definately have 0,0 as coordinates?

Regards

Shelly

0 Kudos