可能重复:
What is the simplest and most robust way to get the user's current location in Android?
我是android的新手。
我只是想知道如何在我的Activity中使用MyLocation类,该类在此链接上发布
What is the simplest and most robust way to get the user's current location on Android?
提前非常感谢你。
答案 0 :(得分:0)
只需在您的活动中调用它:
MyLocation myLocation = new MyLocation();
答案 1 :(得分:0)
MyLocation myLocation = new MyLocation();
private void locationClick() {
myLocation.getLocation(this, locationResult));
}
public LocationResult locationResult = new LocationResult(){
@Override
public void gotLocation(final Location location){
//Got the location!
});
}
};
该代码与您链接的答案逐字逐句。只需创建MyLocation
并传入LocationResult
回调处理程序即可。 gotLocation()
会调用{{1}}。你可以从那里获得经度和纬度。