簡體   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