开发者

Trying to obtain updated locations of android phone but code giving me problems

开发者 https://www.devze.com 2023-02-25 11:20 出处:网络
I am trying to update the location of the phone periodically, but I am getting some errors with my code. Here it is:

I am trying to update the location of the phone periodically, but I am getting some errors with my code. Here it is:

LocationManager locm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
Location location = locm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

double longitude = location.getLongitude();
double latitude = location.getLatitude();



private final 开发者_C百科LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        longitude = location.getLongitude();
        latitude = location.getLatitude();
    }

    locm.requestLocationUpdates(LocationManager.GPS, 2000, 10, locationListener);
        // error here : Syntax error on token(s), misplaced constructs

The thing is, when I take out the last line of code, there are no errors in the code. Can somebody help me please?? Any help would be much appreciated.


You might want to try this nice library project I found. It's nicely documented and is Apache License 2.0.

http://code.google.com/p/little-fluffy-location-library/


You miss the closing bracket in the new location listener.

private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        longitude = location.getLongitude();
        latitude = location.getLatitude();
    }
}; <--


Your last line ("locm.resquestLocationUpdates...") needs to be within a method. It looks like it's directly in a class.

0

精彩评论

暂无评论...
验证码 换一张
取 消