我正在尝试在 Google map V2 中加载我的当前位置。问题是,当我加载应用程序时,我首先看到加载到非洲附近某处的默认 map ,然后在 1 或 2 秒后它动画到当前位置。相反,我想直接显示我的 map 到当前位置,就像谷歌地图或优步那样。
我不确定我哪里出错了。这是我所做的:
initMap()在Fragment的onCreateView中调用。
private boolean initMap()
{
if (googleMap == null)
{
SupportMapFragment mapFrag = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map));
googleMap = mapFrag.getMap();
googleMap.setTrafficEnabled(true);
if (friendslocationclicked == false)
{
googleMap.setMyLocationEnabled(true);
}
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location arg0) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(arg0.getLatitude(), arg0.getLongitude()), ZOOMVALUE));
googleMap.addMarker(new MarkerOptions().position(new LatLng(arg0.getLatitude(), arg0.getLongitude())).title("It's Me!"));
}
});
}
return (googleMap != null);
}
有人可以帮我解决这个问题吗?
谢谢!
最佳答案
Instead of using:-
animateCamera()
使用:- 移动相机() 例如:-
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(arg0.getLatitude(), arg0.getLongitude()), 14.0f));
关于android - 在 Android 中加载谷歌地图中的当前位置并不快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603279/