Could not update the active symbol - Using SVY21 Spatial Reference

813
6
03-04-2013 10:14 PM
RamKola
New Contributor
We are trying to use ESRI Android SDK 2.0 with OneMap server based in Singapore.   (It uses SVY21 spatial reference).  I am able to display the Map on the screen but I keep getting - "Could not update the active symbol java.lang.RuntimeException: Invalid SpatialReference."  

I have tried several approaches including creating the MapView via Java and adding to the Layout.  The other approach using XML is shown below.  I will be grateful if any expert can point me in the right direction.    


Could not update the active symbol
java.lang.RuntimeException: Invalid SpatialReference.
 at com.esri.core.geometry.SpatialReference.nativeGetUnit(Native Method)
 at com.esri.core.geometry.SpatialReference.getUnit(Unknown Source)
 at com.esri.android.map.LocationService$a.k(Unknown Source)
 at com.esri.android.map.LocationService$a$a.onLocationChanged(Unknown Source)



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff000000" >

    <com.esri.android.map.MapView
        android:id="@id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        calloutStyle="@xml/calloutstyle"
        />
</RelativeLayout>



package com.esri.arcgis.android.samples.nearby;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;

import com.esri.android.map.Callout;
import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.LocationService;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.symbol.SimpleMarkerSymbol;

public class SPMap extends Activity {

 private SpatialReference SRef4326;
 private SpatialReference SVY21;

 private MapView map;
 private ArcGISTiledMapServiceLayer tileLayer;
 private LocationService ls;
 protected Point ptCurrentLoc;

 public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);

  this.SRef4326 = SpatialReference.create(4757); // 4326 //ORG - 4757
  // this.svy21 = SpatialReference.create(3414); //For SVY21
  SVY21 = SpatialReference
    .create("PROJCS[\"SVY21\",GEOGCS[\"SVY21[WGS84]\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",28001.642],PARAMETER[\"False_Northing\",38744.572],PARAMETER[\"Central_Meridian\",103.8333333333333],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",1.366666666666667],UNIT[\"Meter\",1.0]]");

  setContentView(R.layout.onemap);
  this.map = ((MapView) findViewById(R.id.map));
  this.tileLayer = new ArcGISTiledMapServiceLayer(
    "http://www.onemap.sg/ArcGIS/rest/services/basemap/MapServer");
  this.map.addLayer(this.tileLayer);

  setupListeners();
 }

 private void setupListeners() {

  this.map.setOnStatusChangedListener(new OnStatusChangedListener() {
   private static final long serialVersionUID = 1L;

   public void onStatusChanged(Object obj, OnStatusChangedListener.STATUS status) {
    if ((obj == SPMap.this.map) && (status == OnStatusChangedListener.STATUS.INITIALIZED)) {
     if (!SPMap.this.map.getSpatialReference().getText().equals(SPMap.this.SVY21.getText())) {
      // Alert if the spatial references dont match
      Log.e("MAP", "Spatial References DONT Match!!");
      // Log.d("MAP", "map.getSpatialReference().getText(): "
      // + obj.getSpatialReference().getText());
      // Log.d("MAP", "this.svy21.getText(): " +
      // SPMap.this.svy21.getText());
     }
     SPMap.this.startLocationService();
    }
   }
  });

 }

 private void startLocationService() {
  try {
   if (this.ls == null) {
    this.ls = this.map.getLocationService();
    this.ls.setAutoPan(false);
    this.ls.setAccuracyCircleOn(true);
    this.ls.setLocationListener(new LocationListener() {
     boolean firstLocation = true;

     public void onLocationChanged(Location paramAnonymousLocation) {
      if (paramAnonymousLocation != null) {

       SPMap.this.ptCurrentLoc = new Point(paramAnonymousLocation.getLongitude(),
         paramAnonymousLocation.getLatitude());
       SPMap.this.ptCurrentLoc = ((Point) GeometryEngine.project(
         SPMap.this.ptCurrentLoc, SPMap.this.SRef4326, SPMap.this.SVY21));

       if (this.firstLocation) {
        this.firstLocation = false;
        SPMap.this.map.zoomTo(SPMap.this.ptCurrentLoc, 50);
       }
      }
     }

     public void onProviderDisabled(String str) {
     }

     public void onProviderEnabled(String str) {
     }

     public void onStatusChanged(String str, int flag, Bundle bundle) {
     }
    });
   }
   this.ls.start();
  } catch (Exception e) {
   // TODO: handle exception
   Log.e("MAP", e.getMessage());
  }
 }

 protected void onResume() {
  super.onResume();
  this.map.unpause();
  startLocationService();
 }
}
0 Kudos
6 Replies
amitm
by
New Contributor
Hi,

   I am also facing same issue. Have you got this issue resolved?


Thanks.
0 Kudos
RamKola
New Contributor
I couldn't find a solution till date.  I am inclined to think that it needs some small piece of code that we are missing. 
It would be great if anyone from ArcGIS could give us a suggestion.  

I do see a few apps in the Android store - Pocket OneMap which are successfully using OneMap as the base-map.

cheers
Ram
0 Kudos
sugunakarreddy
New Contributor
am also getting the same issue here,when i pinch the for zoomin or zoomout these exceptions raised 
i couldn't find the solution.
plz help me if any expert has the solution for this.
E/LocationServce(6176): Could not update the symbol

E/LocationService(6176): java.lang.RuntimeException: Invalid SpatialReference.

E/LocationService(6176):  at com.esri.core.geometry.SpatialReference.nativeGetUnit(Native Method)

E/LocationService(6176):  at com.esri.core.geometry.SpatialReference.getUnit(Unknown Source)

E/LocationService(6176):  at com.esri.android.map.LocationService$a.u(Unknown Source)

this is my code

mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

    private static final long serialVersionUID = 1L;

    public void onStatusChanged(Object source, STATUS status) {
     ls = mMapView.getLocationService();
     if (source == mMapView && status == STATUS.INITIALIZED) {

      ls.setAutoPan(false);
      Log.d(TAG, "working");

      ls.setLocationListener(new LocationListener() {

       boolean locationChanged = true;
                            public void onLocationChanged(Location loc) {
        if (locationChanged) {

         Point mapPoint = null;
         locationChanged = true;
         Log.e(TAG, "it is working");
         double locy = loc.getLatitude();
         double locx = loc.getLongitude();
         Log.e(TAG, "it is working");
         Point wgspoint = new Point(locx, locy);
         Log.e(TAG, "RG X:- " + wgspoint.getX()+ " Y:- " + wgspoint.getY());

        try {
          mapPoint = (Point) GeometryEngine.project(wgspoint,SpatialReference.create(4757),mMapView.getSpatialReference());
                                     }
        catch (Exception e)
              {
          Log.e(TAG, "" + e.toString());
             }
                  graphicsLayer.removeAll();
         mMapView.zoomToScale(mapPoint, 500);
         String msg = "Long:" + locx + "\n" + "Lat:"+ locy;
         Log.d("current location","working");
         Graphic graphic = new Graphic(mapPoint,symbol);
         Log.d("current location","working");
         graphicsLayer.addGraphic(graphic);
         Log.d("current location","working");
             }
        else
        {
        
                                 }

       }

       public void onProviderDisabled(String arg0) {

       }

       public void onProviderEnabled(String arg0) {
       }

       public void onStatusChanged(String arg0, int arg1,Bundle arg2) {

       }

      });
      ls.start();

     }

    }
   });
0 Kudos
SudheeshB
New Contributor
I think this is not the problem with ArcGis. This is bcz of the problem with OneMap. If you use
http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer
then it will work perfectly.

One more chance is the SpatialReference of OneMap is not available in ArcGis list.
0 Kudos
SudheeshB
New Contributor
If you add

locationService.setAccuracyCircleOn(false);


before you start the location service it will work.
0 Kudos
EmmieDacles
New Contributor
I'm also encountering the same issue.  Any update on this one? Thanks.
0 Kudos