【问题标题】:GoogleMaps v2 - How to know when blue dot is diplayedGoogle Maps v2 - 如何知道何时显示蓝点
【发布时间】:2013-08-21 10:58:31
【问题描述】:

我想知道是否有可能知道 GoogleMaps 何时提供/显示代表用户当前位置的蓝点。
事实上,我想显示一个进度条直到那个蓝点已提供,这就是为什么我必须知道后者何时可用。
我目前正在使用 LocationClient 类在调用 connect() 方法后获取用户的位置,但我实际上无法确定它何时获得良好的位置修复(由蓝点表示)。
我还想在可用时放大找到的位置,这就是为什么我使用此回调函数,如果尚未找到修复程序,有时会放大错误的位置。

private LocationResult locDepart = new LocationResult() {       
    @Override
    public void gotLocation(Location location) {    
        Location loc = location;
        if (loc != null) {
            LatLng coordonnees = new LatLng(loc.getLatitude(), loc.getLongitude());
            final CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(coordonnees)      // Sets the center of the map to Mountain View
            .zoom(18)                   // Sets the zoom
            .bearing(90)                // Sets the orientation of the camera to east
            .tilt(10)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
            runOnUiThread(new Runnable () {
                @Override
                public void run() {
                    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
                }           
            });
        } 
        mHandler.sendEmptyMessage(0);
    }
};

感谢您的回答。

【问题讨论】:

    标签: android google-maps-android-api-2


    【解决方案1】:

    使用

    googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
        ...
    });
    

    让自己知道蓝点的位置何时发生变化。

    如果你在启用 myLocation 点之前设置它,你应该在它第一次出现时被回调。

    【讨论】:

    • 感谢您的回答,我已经检查过了,界面已弃用,所以我改用 LocationClient
    • @Sw4Tish 恕我直言,弃用不正确。将setOnMyLocationChangeListener 视为使用LocationClient 和许多不必要的代码可以实现的便捷方法。查看我与自己进行的讨论in this question
    • 我读过它,我必须承认我同意你的观点,因为正如你所说,这是一种方便的方法。因为我认为我无法实现我想要的,所以我可能会使用它。给你接受的答案。
    【解决方案2】:

    您可以用自己的标记替换内置的我的位置功能,因此显示进度条(或busy)应该是微不足道的,除非位置提供者提供了位置修复

    【讨论】:

    • 事实上,蓝点是有效的,所以如果我能让他不使用我自己的标记,我会这样做。我的应用程序是短距离的,所以我必须尽可能准确。
    • Dot 不能高效。这只是图像。因此,您可以自己聆听位置提供者的声音,轻松提高效率
    猜你喜欢
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2014-06-23
    相关资源
    最近更新 更多