繁体   English   中英

Android Google Maps V2用户位置

[英]Android Google Maps V2 User Location

我的地图上没有显示蓝点/箭头。 其他一切都很好。 我错过了一些权限吗?

包括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"/>

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

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));
        }
}

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

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

如果我重新启动,请使用Google Maps v2加载我的应用,然后点击右上角的“转到我的位置”按钮,Archos直接转到我当前的位置,但SGT2什么都不做。

如果我使用位置管理器手动获取当前位置并将地图设置为动画,则会导航。 但是,单击“转到我的位置”按钮仍然无效。

使用GPS获取定位似乎可以解决问题。

编辑:在SGT2上,蓝色位置点仅出现GPS定位,但Archos显示带有移动数据/ wifi修复的蓝点。

嗨,你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;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM