有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓正在寻找我在Java的当前位置

我以前从未使用过安卓软件包,我只是想得到我目前的职位。在网上看了一会儿之后,我已经走到了这一步

import 安卓.location.Location;
import 安卓.location.LocationManager; 
import 安卓.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]);
}

}

问题出在“getSystemService”行:通过阅读javadocs for Context,我知道通过结合Context.LOCATION_SERVICE调用这个方法,我可以得到我当前的位置,但我真的不知道如何调用getSystemService。任何帮助都将不胜感激,我相信这是一个简单的问题,我只是不理解我正在使用的类


共 (0) 个答案