【发布时间】:2013-06-06 18:26:26
【问题描述】:
我正在将 GooglepMap V2 嵌入到我的 Android APP (2.2) 中,但是当我尝试在我的设备中进行缩放或导航到地图时,移动速度太慢,有时事件(缩放或导航)不会不行。我可以在传播事件时遇到问题吗?可能是什么问题?
布局图:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
谷歌地图活动:
public class GoogleMapActivity extends FragmentActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.template);
LinearLayout l = (LinearLayout) findViewById(R.id.info);
LinearLayout left = new LinearLayout(this);
...
LinearLayout right = new LinearLayout(this);
...
addMap(right);
l.addView(right);
}
RelativeLayout mapRelative;
private final LatLng UPV = new LatLng(39.481106, -0.340987);
private GoogleMap mapa;
public void addMap(LinearLayout main){
LayoutInflater inflater = LayoutInflater.from(GoogleMapActivity.this);
mapRelative = (RelativeLayout)inflater.inflate(R.layout.map, null, false);
main.addView(mapRelative);
}
@Override
protected void onResume() {
super.onResume();
mapa = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mapa != null) {
mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(UPV, 15));
mapa.setMyLocationEnabled(true);
mapa.getUiSettings().setAllGesturesEnabled(true);
}
}
}
【问题讨论】:
-
为什么要添加两次地图?您已经在 xml 中将其声明为静态片段,您无需在
addMap方法中再次添加它 -
我有两 (2) 个 xml,主 xml 名为 R.layout.template(应用程序的通用视图)和 R.layout.map 用于我想包含在第一个中的 Googlemap使用 addMap
-
但您仍在添加 2 张地图,这可能是您的问题。摆脱在您已在 xml 中添加的代码中添加地图
标签: android google-maps navigation zooming gestures