我遇到了将Google地图摄像机移回初始位置的问题。基本上,我在Actionbar上有一个主页按钮。如果用户在地图上滚动并点击主页按钮,则希望摄像机移回其原始位置。
我使用googleMap.getCameraPosition().target
获取原始坐标,但摄像机不会移动。
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
LatLng initialLoc= mMap.getCameraPosition().target;
CameraUpdate update = CameraUpdateFactory.newLatLng(initialLoc);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
mMap.moveCamera(update);
mMap.animateCamera(zoom);
return true;
}
地图.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="org.test"
android:name="com.google.android.gms.maps.SupportMapFragment"
map:cameraTargetLat="xxx.xxx"
map:cameraTargetLng="xxx.xxx"
map:cameraZoom="15"
map:mapType="normal" />
</RelativeLayout>
我错过了什么?
cameraTargetLat
和cameraTargetLon
定义的。我该如何以编程方式检索它们? - Pangu