ramkola

Could not update the active symbol - Using SVY21 Spatial Reference

Discussion created by ramkola on Mar 4, 2013
Latest reply on Jul 24, 2013 by meg0702
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();
 }
}

Outcomes