I've never used the android packages before, and I just want to get my current position. After looking online a bit, I've gotten this far.
import android.location.Location;
import android.location.LocationManager;
import android.content.*;
public class CurPosGetter{
public static double[] getPosition(){
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = (Location) lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
double[] ans = new double[2];
ans[0] = latitude;
ans[1] = longitude;
return ans;
}
public static void main (String [] args){
double[] pos = getPosition();
System.out.println(pos[0] + " , " + pos[1]);
}
}
The problem is at the 'getSystemService' line: by reading the javadocs for Context I understand that by calling this method in conjunction with Context.LOCATION_SERVICE
I can get my current position, but I don't really understand how to call getSystemService. Any help would be appreciated, I'm sure this is a simple issue and I just don't understand the classes I'm using.