我做什么: 我使用诺基亚Here-maps包装器v2来显示带有一个自定义标记和用户位置的地图。然后我使用PolyLines在这两个点之间绘制方向。一切正常,使用Google Play服务但在诺基亚X上我无法获得用户位置,在地图对象上调用setMyLocationEnabled会抛出:
java.lang.IllegalArgumentException:提供者不存在:null at android.os.Parcel.readException(Parcel.java:1435)at android.os.Parcel.readException(Parcel.java:1385)at android.location.ILocationManager $存根$ Proxy.requestLocationUpdates(ILocationManager.java:540) 在 android.location.LocationManager.requestLocationUpdates(LocationManager.java:836) 在 android.location.LocationManager.requestLocationUpdates(LocationManager.java:430) 在com.nokia.maps.DeviceLocation.M(DeviceLocation.java:380)at com.nokia.maps.DeviceLocation.start(DeviceLocation.java:107)at com.nokia.maps.PositioningManager.start(PositioningManager.java:171) 在 com.nokia.android.gms.maps.GoogleMap.setPositionManagerEnabled(GoogleMap.java:1442) 在 com.nokia.android.gms.maps.GoogleMap.setMyLocationEnabled(GoogleMap.java:1420) 在 com.nokia.android.gms.maps.GoogleMap.onInitializationComplete(GoogleMap.java:696) 在 com.nokia.android.gms.maps.MapView.attachMapToMapViewSetup(MapView.java:293) 在com.nokia.android.gms.maps.MapView.access $ 19(MapView.java:271)at at com.nokia.android.gms.maps.MapView $ 4.onFactoryInitializationCompleted(MapView.java:263) 在com.nokia.maps.MapFactory $ 2.run(MapFactory.java:455)
清单
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:hardwareAccelerated="true" >
<uses-library android:name="com.here.android" android:required="false" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_GOOGLE_APIV2_KEY"/>
<meta-data android:name="com.here.android.maps.appid" android:value="MY_HERE_APPID" />
<meta-data android:name="com.here.android.maps.apptoken" android:value="MY_HERE_TOKEN" />
<activity
android:name=".MapsFragmentActivity"
android:label="@string/title_activity_maps" >
</activity>
</application>
地图片段布局
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.nokia.android.gms.maps.SupportMapFragment" />
地图片段活动类
public class StadiumsMapsFragmentActivity extends FragmentActivity {
private MapsFragmentLegacy mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapactivity);
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
try {
if(mMapFragment == null) {
if (MyWrapper.hasHere(context)) {
mMapFragment = new MapsFragmentHere();
} else {
mMapFragment = new MapsFragmentGoogle();
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.map_container, mMapFragment).commit();
}
}
catch(Exception e){
if(DEBUG)e.printStackTrace();
}
}
}
MapsFragmentHere class
import com.nokia.android.gms.maps.CameraUpdateFactory;
import com.nokia.android.gms.maps.GoogleMap;
import com.nokia.android.gms.maps.SupportMapFragment;
import com.nokia.android.gms.maps.model.BitmapDescriptorFactory;
import com.nokia.android.gms.maps.model.LatLng;
import com.nokia.android.gms.maps.model.MarkerOptions;
import com.nokia.android.gms.maps.model.PolylineOptions;
public class MapsFragmentHere extends MapsFragmentLegacy {
private GoogleMap mMap;
private LatLng mLatLng;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
FRAGMENT_LAYOUT = R.layout.hmaps;
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(FRAGMENT_ID);
mMap = mapFragment.getMap();
setUpMap();
}
private GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
LatLng origin = new LatLng(location.getLatitude(), location.getLongitude());
// Draw direction if needed
}
};
private void setUpMap() {
if(mMap != null) {
mLatLng = new LatLng(LATITUDE, LONGITUDE);
mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
.title("title")
.snippet("")
.position(mLatLng));
mMap.setOnMyLocationChangeListener(myLocationChangeListener);
}
}
}
MapsFragmentLegacy class
public class MapsFragmentLegacy extends Fragment {
protected static int FRAGMENT_LAYOUT = R.layout.maps;
protected static final int FRAGMENT_ID = R.id.map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(FRAGMENT_LAYOUT, container, false);
}
}
使用相机位置,初始变焦,工作缩放控件和自定义标记正确显示地图。 任何帮助将不胜感激:)