我的位置和标记有不同的位置 [英] My location and marker have different locations

查看:115
本文介绍了我的位置和标记有不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的位置和标记有不同的位置?在添加标记之前,我点击浮动按钮,当点击它时,我从<$>调用 getLatitude getLongitude C $ C>的LocationManager 。这与当地图准备好并移动摄像头时相似,所以我认为标记和mylocation必须相同:



这是我的代码:

  private class MyLocationListeners implements LocationListener { 
@Override
public void onLocationChanged(Location location){
longitude = null;
latitude = null;

longitude = String.valueOf(location.getLongitude());
Log.d(TAG,onLocationChanged1:+ longitude);

latitude = String.valueOf(location.getLatitude());
Log.d(TAG,onLocationChanged2:+ latitude);

$ b @Override
public void onStatusChanged(String provider,int status,Bundle extras){

}

@Override
public void onProviderEnabled(String provider){
$ b}

@Override
public void onProviderDisabled(String provider){





$ b $ p $ MyLocationListener

  locationListener = new MyLocationListeners(); 
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
5000,
10,
locationListener
);


解决方案

我的位置图层使用它自己的位置提供商,它不是融合位置提供商或位置管理器。从文档


GoogleMap对象为其位置图层提供了一个内置位置提供程序,但可以用另一个实现此接口的位置提供程序替换。

此外,我的位置图层,融合位置提供程序和位置管理器可以获得不同的位置(取决于提供程序, GPS和网络可用性等)。

您可以使用 GoogleMap.setLocationSource 方法。


Why does my location and marker have different locations? Before adding the marker I click on the floating button and when I click that, I call getLatitude and getLongitude from LocationManager. It's similar to when the is map ready and move camera so I think the marker and mylocation must be the same:

This is my code:

private class MyLocationListeners implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        longitude = null;
        latitude = null;

        longitude = String.valueOf(location.getLongitude());
        Log.d(TAG, "onLocationChanged1: " + longitude);

        latitude = String.valueOf(location.getLatitude());
        Log.d(TAG, "onLocationChanged2: " + latitude);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {

    }
}

Code where I set MyLocationListener:

locationListener = new MyLocationListeners();
locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER,
        5000,
        10,
        locationListener
);

解决方案

The My location layer uses it's own location provider that is not the Fused Location Provider nor the Location Manager. From the documentation:

A GoogleMap object has a built-in location provider for its my-location layer, but it can be replaced with another one that implements this interface.

Also, the My location layer, the Fused Location provider and the Location Manager can get different locations (it depends on the provider, the GPS and network availability, ...).

You can replace the default location provider for the my-location layer using the GoogleMap.setLocationSource method.

这篇关于我的位置和标记有不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆