2012-12-07 29 views
5

藍點/箭頭顯示的心不是我的地圖上。其他一切正常。我缺少一些權限?Android的谷歌地圖V2用戶位置

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

是否與谷歌地圖應用工作在這個設備上?在較新版本的Android中存在一個問題,您必須特別通過「設置」應用的「帳戶」區域授予Google地圖權限才能使用GPS。可以想象,這也會影響V2 Maps的內容。 – CommonsWare

+0

可悲的是藍點顯示了罰款,在我的三星Galaxy S2 –

+0

中的設備我的應用程序設置的谷歌地圖應用程序甚至說,這個應用程序可以訪問「我的位置」(也有「網絡通信」) –

回答

0

由於某種原因,它只是工作。離開午餐,離開了應用程序。當我回到地圖上繪製的藍色箭頭。雖然不在正確的位置,但它在地圖上。所以我的發佈代碼工作。它只需要位置管理器的更新。

+0

當我運行旅遊代碼時,它給了我錯誤:** java.lang.ClassCastException:android.support.v4.app.NoSaveStateFrameLayout無法轉換爲com.google.android.gms.maps.MapView ** 我使用Google Inc. :Google API:10和MAP V2。 –

3

你會看到,點擊 '我的位置' 按鈕創建在當前位置的藍色圓點。使用位置管理器跟蹤位置更新並相應地移動攝像頭,您可以跟蹤用戶,而無需點擊按鈕。查看下面的代碼片段。

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

你在哪裏註冊這個聽衆?它是在'LocationManager'系統服務而不是'Map'嗎? – dnkoutso

+0

點擊我的位置按鈕甚至不會在我的情況下創建藍點。 –

+0

是的,LocationManager,如:LocationManager.requestLocationUpdates(provider,time,distance,LocationListener); – soujisama

0

FWIW,我有三星Galaxy Tab 2上的原始帖子完全相同的問題。 但是,我沒有在愛可視101G9上的問題。

如果我重新啓動,加載我與谷歌地圖V2應用,然後點擊右上角的「去我的位置」按鈕,愛可視直接轉到我的當前位置,但SGT2什麼都不做。

如果我使用位置管理器手動讓我的當前位置,並給它,然後它動畫導航地圖。然而,點擊「去我的位置」按鈕仍然沒有任何作用。

獲取使用GPS位置定位似乎解決這個問題。

編輯: 在SGT2上的藍色位置點只出現一個GPS定位,但是愛可視顯示藍色點與移動數據/無線固定。

0

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

和實施methos到LocationListener的;)