【问题标题】:Android zoom in and center around custom marker in a mapAndroid 在地图中放大并围绕自定义标记居中
【发布时间】:2015-08-31 15:41:57
【问题描述】:

我正在使用 Google 地图 API V2。我已禁用 map.isMyLocationEnabled(),因此我使用自己的自定义图标代替蓝点。由于我的位置图层已禁用,因此地图不会在我的图标周围放大。有人能指点我怎么做吗?

GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
                @Override
                public void onMyLocationChange (Location location) {
                   LatLng loc = new LatLng (location.getLatitude(), location.getLongitude());

                   if (marker != null) {
                        marker.remove(); // remove the old marker
                    }
                    marker = map.addMarker(new MarkerOptions()
                            .position(loc)
                            .draggable(true)
                            .title("Not your location? wait 10 few seconds until the icon displays your real location")
                            .visible(true)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.mmyicon))
                            .flat(true));   // allows it rotate with the earth and change
                                            // perspective as needed and retain it's
                                            // size
                    map.moveCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15));
                //startIntentService(location);
                }
            };
            map.setOnMyLocationChangeListener(myLocationChangeListener);

【问题讨论】:

  • 你好@The_Martian 你能帮我评论这条评论吗?我也想在我的应用程序中使用相同的功能。 “我正在根据另一个应用程序的实时位置更新来制作汽车位置动画。那么,当我只有当前位置时,如何获取 LatLng 列表?有没有办法可以延迟应用程序的绘制以收集一些更新然后将所有内容添加到 List 对象并将其传递给您的方法并继续重复直到最终目的地?”。
  • 我会说将绘图延迟几秒钟并将 LatLng 对象添加到列表中,然后循环遍历它们并将它们绘制在地图上。 Google 道路 api 有很好的文档说明如何使用我提到的相同技术消除噪音并在道路上画线。

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


【解决方案1】:

在您通过map.setMyLocationEnabled(false) 禁用 myLocation 层后,此侦听器也无法正常工作。

所以你应该通过另一种方式接收位置。 https://developer.android.com/training/location/receive-location-updates.html

设置正确后,您可以在此回调上绘制标记。

@Override
public void onLocationChanged(Location location) {
    ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2017-05-31
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    相关资源
    最近更新 更多