package io.myweb.examples;

import android.content.Context;
import android.location.Location;
import android.location.LocationManager;

import org.json.JSONException;
import org.json.JSONObject;

import io.myweb.api.GET;

public class LocationExample {
	private LocationManager lm;

	@GET("/location/*provider")
	public JSONObject location(Context context, String provider) throws JSONException {
		lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		if (provider.length()==0) {
			JSONObject loc = new JSONObject();
			for (String p : lm.getAllProviders()) {
				loc.put(p, getLocationFromProvider(p));
			}
			return loc;
		}
		return getLocationFromProvider(provider);
	}

	private JSONObject getLocationFromProvider(String provider) throws JSONException {
		Location l = lm.getLastKnownLocation(provider);
		JSONObject jl = new JSONObject();
		if (l!=null) {
			jl.put("provider", provider);
			jl.put("longitude", l.getLongitude());
			jl.put("latitude", l.getLongitude());
			jl.put("time", l.getTime());
			if (l.hasAccuracy()) jl.put("accuracy", l.getAccuracy());
			if (l.hasAltitude()) jl.put("altitude", l.getAltitude());
			if (l.hasBearing()) jl.put("bearing", l.getBearing());
			if (l.hasSpeed()) jl.put("speed", l.getSpeed());
		}
		return jl;
	}
}

@@ -586,45 +586,146 @@
 %09%09%09%09
-loc.put(p, getLocationFromProvider(p)
+JSONObject provAccuracy = new JSONObject();%0A%09%09%09%09provAccuracy.put(%22accuracy%22, lm.getProvider(p).getAccuracy());%0A%09%09%09%09loc.put(p, provAccuracy
 );%0A%09
@@ -1077,35 +1077,34 @@
 atitude%22, l.getL
-ong
+at
 itude());%0A%09%09%09jl.

Fix latitude in location example