gpt4 book ai didi

android - 如何获取 GPS 位置?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:03 29 4
gpt4 key购买 nike

我正在尝试获取位置,但总是出现错误。你们中的任何人都能看到我要去哪里错了吗?其中一个错误至少是“方法没有覆盖或实现父类(super class)型的方法”——非常感谢你们

主要

@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//get Your Current Location
LocationManager locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyCurrentLoctionListener locationListener = new MyCurrentLoctionListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) locationListener);

}

MyCurrentLoctionListener 类

public class MyCurrentLoctionListener implements LocationListener {

@Override
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();

String myLocation = "Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude();

//I make a log to see the results
Log.e("MY CURRENT LOCATION", myLocation);

}

@Override
public void onStatusChanged(String s, int i, Bundle bundle) {

}

@Override
public void onProviderEnabled(String s) {

}

@Override
public void onProviderDisabled(String s) {

}
}

在安卓 list 中:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

最佳答案

您不需要@Override 当前正在覆盖的方法。它们已经是抽象的 void,所以通过实现类,它假设你是。看看 Android tutorial用于获取位置信息。

public class MyCurrentLoctionListener implements LocationListener {

public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();

String myLocation = "Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude();

//I make a log to see the results
Log.e("MY CURRENT LOCATION", myLocation);

}

public void onStatusChanged(String s, int i, Bundle bundle) {

}

public void onProviderEnabled(String s) {

}

public void onProviderDisabled(String s) {

}
}

关于android - 如何获取 GPS 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25048834/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com