-1

是否有任何代码可以让您在自制应用程序中显示您的活动坐标?我的谷歌地图有问题,想看看我的活动坐标是什么。我更喜欢在我的应用程序中查看谷歌地图时显示它,例如第二层信息。谢谢大家!

4

1 回答 1

3

您可以设置一个 LocationListener。

在 onLocationChanged 回调中,您将收到一个位置。然后,您可以从该位置 .getLatitude() 和 .getLongitude() 并将其应用于您的布局。

public class MyActivity extends MapActivity implements LocationListener {

    private LocationManager locationManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        requestFineAccuracyLocationUpdates();
    }

    private void requestFineAccuracyLocationUpdates() {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);

        List<String> providers = locationManager.getProviders(true);

        for (String provider : providers) {
            locationManager.requestLocationUpdates(provider, 5000, 1000, this);
        }
    }

    @Override
    public void onLocationChanged(Location location) {
        /* You can get your latitude and longitude here, and do whatever. */
    }
}
于 2012-06-26T21:41:05.647 回答