【问题标题】:Android Google Maps V2 User LocationAndroid 谷歌地图 V2 用户位置
【发布时间】:2012-11-25 19:18:55
【问题描述】:

我的地图上没有显示蓝点/箭头。其他一切正常。我是否缺少一些权限?

包括 Java 类、清单和布局 XML。

private void setUpMap(int satelliteMode, LatLng startPoint, float zoomLevel) {

        mapView.getUiSettings().setZoomControlsEnabled(false);
        //mapView.getUiSettings().setMyLocationButtonEnabled(false);
        mapView.setMapType(satelliteMode);
        mapView.setMyLocationEnabled(true);
        mapView.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint, zoomLevel));
    }

xml:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

清单:

<permission
         android:name="com.example.project.MAPS_RECEIVE"
         android:protectionLevel="signature"/>
    <uses-permission  android:name="com.example.project.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <meta-data
           android:name="com.google.android.maps.v2.API_KEY"
           android:value="API_KEY"/>

【问题讨论】:

  • 它可以与此设备上的 Google 地图应用程序一起使用吗?在较新版本的 Android 中存在一个问题,您必须特别通过“设置”应用的“帐户”区域授予 Google 地图的权限,以便它能够使用 GPS。可以想象,这也会影响 V2 Maps 的东西。
  • 遗憾的是,蓝点在我的三星 Galaxy s2 上的谷歌地图应用程序中显示良好
  • 我的应用的设备内设置甚至说这个应用可以访问“你的位置”(也有“网络通信”)
  • 我只想指出,我目前遇到了同样的问题,代码几乎相同:/
  • 所以没有人可以解决这个问题?希望安卓能尽快解决这个问题。

标签: java android eclipse google-maps geolocation


【解决方案1】:

您会看到点击“我的位置”按钮会在您当前的位置创建蓝点。使用位置管理器跟踪位置更新并相应地移动相机允许您也跟踪用户,而无需单击按钮。请参阅下面的 sn-p。

LocationListener ll = new LocationListener() {

        @Override
        public void onLocationChanged(Location arg0) {
            Toast.makeText(getBaseContext(), "Moved to "+arg0.toString(), Toast.LENGTH_LONG).show();
            CameraPosition cp = new CameraPosition.Builder()
            .target(new LatLng(arg0.getLatitude(),arg0.getLongitude()))
            .zoom(12)
            .build();     
            map.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
        }
}

【讨论】:

  • 你在哪里注册这个监听器?是在LocationManager 系统服务上而不是Map 上吗?
  • 单击我的位置按钮甚至不会在我的情况下创建蓝点。
  • 是的,LocationManager,如:LocationManager.requestLocationUpdates(provider, time, distance, LocationListener);
  • @MarkMolina 你是如何初始化mapView的?我使用:GoogleMap map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
  • 完全一样: public void setUpMapIfNeeded(int satelliteMode, LatLng startPoint, float zoomLevel) { // 做一个空检查来确认我们还没有实例化地图。 if (mapView == null) { mapView = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview)) .getMap(); // 检查我们是否成功获取地图。 if (mapView != null) { setUpMap(satelliteMode, startPoint, zoomLevel); } } }
【解决方案2】:

由于某种原因,它刚刚起作用。去吃午饭,然后打开应用程序。当我返回时,蓝色箭头绘制在地图上。虽然不在正确的位置,但它在地图上。所以我发布的代码有效。它只需要位置管理器的更新。

【讨论】:

  • 当我运行游览代码时,它给了我错误 java.lang.ClassCastException: android.support.v4.app.NoSaveStateFrameLayout 不能转换为 com.google.android.gms.maps。 MapView 我也使用 Google Inc.:Google APIs:10 和 MAP V2。
【解决方案3】:

FWIW,我的问题与三星 Galaxy Tab 2 上的原始帖子完全相同。 但是,我在爱可视 101G9 上没有这个问题。

如果我重新启动,使用 Google Maps v2 加载我的应用程序并单击右上角的“转到我的位置”按钮,Archos 会直接转到我当前的位置,但 SGT2 什么也不做。

如果我使用位置管理器手动获取当前位置并将地图动画化到该位置,则它会导航。但是,单击“转到我的位置”按钮仍然没有任何作用。

使用 GPS 进行定位似乎可以解决问题。

编辑: 在 SGT2 上,蓝色位置点仅在 GPS 定位时出现,但爱可视显示蓝点,并带有移动数据/wifi 定位。

【讨论】:

    【解决方案4】:

    你好 FragmentActivity 添加实现 LocationListener

    private LocationManager locationManager;
    

    onCreate(Bundle savedInstanceState)....中添加

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    
    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);       locationManager.requestLocationUpdates(locationManager.getBestProvider(locationCriteria, true), 1L, 2F, this);
    

    并实现了 LocationListener 的方法;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      相关资源
      最近更新 更多