我在支持 2.3.3 的 android 应用程序中使用 maps api v2,并且我设置了 setMyLocationEnabled(true),当然我的按钮在果冻豆上工作正常,但在 2.3.3 上不工作。
以下是我如何称呼地图:
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap(){
mMap.setMyLocationEnabled(true);
if(ttdBranch!=null){
mMap.addMarker(new MarkerOptions()
.position(new LatLng(ttdBranch.getLatitude(), ttdBranch.getLongitude()))
.snippet(getResources().getString(R.string.branch) + "\n" + ttdBranch.getName()));
LatLng pos = new LatLng(ttdBranch.getLatitude(),ttdBranch.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pos, 14));
}
}
这是清单:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<permission android:name="*******.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="*******.permission.MAPS_RECEIVE"/>
<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.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_ttd_petales"
android:label="@string/app_name"
android:theme="@style/Holo.Theme.Light" >
<activity
android:name="*******.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="*******.BranchesMapActivity" />
<activity android:name="*******.BranchDetailActivity"/>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="*******"/>
我确保在手机上启用了位置传感器,并且它在谷歌地图应用程序上工作,但不在我的应用程序中。
有什么帮助吗?
谢谢。