Code example for JSONStringer

Methods: endObject, key, object, toString, value

0
		} 
		@Override 
		public void onLocationChanged(Location loc) {
			Log.i(TAG,"Location provider="+loc.getProvider()+", lat="+loc.getLatitude()+", long="+loc.getLongitude()+", bearing="+(loc.hasBearing() ? ""+loc.getBearing() : "NA")+", speed="+(loc.hasSpeed() ? ""+loc.getSpeed() : "NA")+", accuracy="+(loc.hasAccuracy() ? ""+loc.getAccuracy() : "NA")+", alt="+(loc.hasAltitude() ? ""+loc.getAltitude() : "NA"));
			try { 
				JSONStringer js = new JSONStringer();
				// as er Aether's notebook 
				js.object();
				js.key("accuracy");
				if(loc.hasAccuracy())
					js.value(loc.getAccuracy());
				else 
					js.value(null);
				 
				js.key("altitude");
				if(loc.hasAltitude())
					js.value(loc.getAltitude());
				else 
					js.value(null);
				 
				js.key("bearing");
				if(loc.hasBearing())
					js.value(loc.getBearing());
				else 
					js.value(null);
				 
				js.key("latitude");
				js.value(loc.getLatitude());
				 
				js.key("longitude");
				js.value(loc.getLongitude());
				 
				js.key("provider");
				js.value(loc.getProvider());
				 
				js.key("speed");
				if(loc.hasSpeed())
					js.value(loc.getSpeed());
				else 
					js.value(null);
				 
				Bundle extras = loc.getExtras();
				js.key("extras");
				if(extras != null)
					js.value(extras.toString());
				else 
					js.value(null);
 
				js.endObject();
				LoggingUtils.log(LOGTYPE_LOCATION, js.toString());
			} 
			catch (Exception e) {
				Log.e(TAG,"Logging "+loc);
			} 
			ZoneService.updateLocation(context, loc);