2017-04-15 30 views
0

我是新来这里映射目前正试图从定位经理获取当前用户位置,的getLocation()方法,但我的代码总是返回以下信息安卓:HERE地图定位经理为getPosition()总是返回纬度:17976931348623200 ..,经度:17976931348623200

com.nokia.maps.GeoPositionImpl [坐标=会有地理座标[纬度= -179769313486232000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000经度= -1797693134862320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000高度= 1073741824.000000有效值= FALSE]

下面是我的代码:

 protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      //requestPermissions(); 

      // Search for the Map Fragment 
      final MapFragment mapFragment = (MapFragment) 
        getFragmentManager().findFragmentById(R.id.mapfragment); 
    // initialize the Map Fragment and 
    // retrieve the map that is associated to the fragment 
      mapFragment.init(new OnEngineInitListener() { 
       @Override 
       public void onEngineInitializationCompleted(
         OnEngineInitListener.Error error) { 
        if (error == OnEngineInitListener.Error.NONE) { 
    // now the map is ready to be used 
         map = mapFragment.getMap(); 

         onMapFragmentInitializationCompleted(); 
     } else { 
         System.out.println("ERROR: Cannot initialize MapFragment"); 
         System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString()); 
        } 
       } 
      }); 

     } 




    private void onMapFragmentInitializationCompleted() { 
      PositioningManager posManager; 
      MapContainer placesContainer = null; 
      // retrieve a reference of the map from the map fragment 
      // map = mapFragment.getMap(); 
      // start the position manager 
      posManager = PositioningManager.getInstance(); 
      posManager.start(PositioningManager.LocationMethod.GPS_NETWORK); 

      GeoPosition position = posManager.getPosition(); 
      GeoCoordinate cor = position.getCoordinate(); 

      // Set a pedestrian friendly map scheme 
      map.setMapScheme(Map.Scheme.PEDESTRIAN_DAY); 

      // Display position indicator 
      map.getPositionIndicator().setVisible(true); 

      placesContainer = new MapContainer(); 
      map.addMapObject(placesContainer); 

      // Set the map center coordinate to the current position 
      map.setCenter(posManager.getPosition().getCoordinate(), Map.Animation.NONE); 
      map.setZoomLevel(14); 
     } 


Manifest.xml 

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.benz.event.navigation"> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="navigation" 
     android:hardwareAccelerated="true" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 


     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <meta-data android:name="com.here.android.maps.appid" android:value="MY ID"/> 
     <meta-data android:name="com.here.android.maps.apptoken" android:value="MY TOKEN"/> 
     <meta-data android:name="com.here.android.maps.license.key" android:value="MY KEY"/> 



     <!-- 
      Embed the HERE Map Service. 
      For more information, see the HERE SDK Developer's Guide 
     --> 
     <service 
      android:name="com.here.android.mpa.service.MapService" 
      android:label="HereMapService" 
      android:process="global.Here.Map.Service.v2" 
      android:exported="true" > 
      <intent-filter> 
       <action android:name="com.here.android.mpa.service.MapService" > 
       </action> 
      </intent-filter> 
     </service> 



    </application> 





</manifest> 

任何帮助/提示将节省我的一天

感谢

回答

0

有效值= false表示您的设备不有一个GPS锁。您的设备是否在室内并无法获得位置?其次,请检查您的应用程序是否具有定位权限。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION " /> 
+0

谢谢大卫对你的反应,结果是相同与室内和室外场景(在我的谷歌应用程序定位工作正常,所以我认为它可能不是设备的问题),我已经有必要的权限添加我的清单,仍然没有运气 – Khan

+0

您构建应用程序的SDK目标是什么?我在你的代码片段中看到你注释掉了requestPermissions(),这意味着应用程序正在使用旧的权限模型? –

+0

详情如下:已遵守版本:compileSdkVersion 25 :: buildToolsVersion “25.0.0” :: 15的minSdkVersion :: targetSdkVersion 22,目前我使用的华硕平板电脑p01z拥有的Android 5.0.2 API 21在里面,这是一个问题? – Khan