简体   繁体   English

Android 放大并以地图中的自定义标记为中心

[英]Android zoom in and center around custom marker in a map

I am using Google map API V2.我正在使用谷歌地图 API V2。 I have disabled the map.isMyLocationEnabled() so I use my own custom icon in place of the blue dot.我已禁用 map.isMyLocationEnabled(),因此我使用自己的自定义图标代替蓝点。 Since the my location layer is disabled the map doesn't zoom in around my icon.由于我的位置图层被禁用,地图不会围绕我的图标放大。 Can someone point me on how to do that?有人可以指出我该怎么做吗?

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);

After you disable myLocation layer by map.setMyLocationEnabled(false) , this listener become not working too.通过map.setMyLocationEnabled(false)禁用 myLocation 层后,此侦听器也无法正常工作。

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

After you set everything correct you can draw marker on this callback.设置正确后,您可以在此回调上绘制标记。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM