永远不会调用GoogleMaps.oncameraChangedListener

编程入门 行业动态 更新时间:2024-10-20 07:40:30
本文介绍了永远不会调用GoogleMaps.oncameraChangedListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个实现GoogleMap.onCameraChangedListener的Activity(会放大地图片段),并且我已经覆盖了onCameraChange方法.

I have an Activity (which inflates a map fragment) which implements the GoogleMap.onCameraChangedListener, and I have overriden the onCameraChange method.

问题是,每当我在地图上移动时,即相机位置发生变化,就永远不会调用onCameraChange方法.

The problem is that whenever I move across the map, i.e. the camera position changes, the onCameraChange method is never called.

这可能是什么原因造成的?

What could be causing this?

推荐答案

尝试一下:

public class MapActivity extends AppCompatActivity implements GoogleMap.OnCameraChangeListener{ private GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.googlemap_layout); setUpMapIfNeeded(); } @Override public void onCameraChange(CameraPosition cameraPosition) { double latitude = cameraPosition.target.latitude; double longitude = cameraPosition.target.longitude; } private void setUpMapIfNeeded() { if (googleMap == null) { // Try to obtain the map from the SupportMapFragment. googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (googleMap != null) { googleMap.setMyLocationEnabled(true); googleMap.getUiSettings().setMyLocationButtonEnabled(true); googleMap.getUiSettings().setRotateGesturesEnabled(false); googleMap.getUiSettings().setZoomControlsEnabled(false); googleMap.setOnCameraChangeListener(this); } } }

}

布局:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="schemas.android/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" /> </RelativeLayout>

更多推荐

永远不会调用GoogleMaps.oncameraChangedListener

本文发布于:2023-11-26 20:55:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635158.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:永远不会   GoogleMaps   oncameraChangedListener

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!