【发布时间】:2015-08-22 23:30:15
【问题描述】:
我无法将 Google 地图相机移回初始位置。基本上,我在操作栏上有一个主页按钮。如果用户在地图上滚动并点击主页按钮,我希望相机移回其原始位置。
我使用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;
}
map.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>
我错过了什么?
【问题讨论】:
标签: android google-maps