android - 在 Android 中加载谷歌地图中的当前位置并不快

标签 android google-maps google-maps-android-api-2 google-maps-api-2

我正在尝试在 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/

相关文章:

android - JsonMappingException : Infinite recursion on OneToMany Relationship in Objectify

android - 将 android 应用程序发布到市场 - 个人开发者

android - Mosby MVI - 如何重用 Presenter

javascript - 谷歌地图 v3 : Marker and infowindow is not displaying

swift - Xcode 9.2 : linker command failed with exit code 1 (use -v to see invocation)

android - Android 2.2 中的 GOOGlE API V2 问题

java - 如何使用坐标在 map android上查找位置

jquery - 使用 Jquery 的类似 Tabbar 的效果

javascript - 谷歌地图无法正常显示

android - 在 Android google maps api v2 for 4.0 中,显示从当前位置到给定经纬度的路线