在我的xml中我有这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contactusscene"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ContactUsScene" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="400dp"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
在像这样的代码中
mMap = mapfm.getMap();
mMap.setTrafficEnabled(true);
UiSettings settings = mMap.getUiSettings();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(new CameraPosition(new LatLng(10.23454,
123.5543534), 13.5f, 30f, 112.5f)));
mMap.setTrafficEnabled(true);
settings.setAllGesturesEnabled(true);
settings.setCompassEnabled(true);
settings.setMyLocationButtonEnabled(true);
settings.setRotateGesturesEnabled(true);
settings.setScrollGesturesEnabled(true);
settings.setTiltGesturesEnabled(true);
settings.setZoomControlsEnabled(true);
settings.setZoomGesturesEnabled(true);
在日志中,它继续运行此并且无法显示位置和地图。它只有银色。
05-25 20:50:33.689: E/Adreno200-EGLSUB(11275): Enter: GetBackBuffer(), surface: 0x3ef488, bufid: 0
05-25 20:50:33.689: E/Adreno200-EGLSUB(11275): Return: GetBackBuffer(), TRUE
05-25 20:50:33.709: E/Adreno200-EGLSUB(11275): Enter: GetBackBuffer(), surface: 0x3ef488, bufid: 1
05-25 20:50:33.709: E/Adreno200-EGLSUB(11275): Return: GetBackBuffer(), TRUE
答案 0 :(得分:0)
在AndroidManifest.xml
<permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
<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.WRITE_EXTERNAL_STORAGE"/>
<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"/>
在<application>
标记内添加以下代码。用您的api密钥替换 API密钥。
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value=" API Key"/>
从FragmentActivity
扩展您的活动。
然后使用下面的代码。
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment) myFragmentManager
.findFragmentById(R.id.map);
GoogleMap myMap = mySupportMapFragment.getMap();
然后用myMap
对象做你的东西。
答案 1 :(得分:0)
用户这样:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
你的活动:
public class showMaps extends AbstractMapActivity {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if (readyToGo()) {
setContentView(R.layout.showmaps);
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = mapFrag.getMap();
}
}
}
以下是AbstractMapActivity.java在您的代码中添加此文件:
如果需要,可以使用fullcode。
确保您已添加所有必需的权限,openGL,MAP API密钥(您自己的密钥)。
了解地图的更多详情android-manifest。
答案 2 :(得分:0)
试试这个:
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
// what you want to do
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
}
然后你必须添加:
if (googleMap == null) {
// Try to obtain the map from the SupportMapFragment.
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
googleMap.setMyLocationEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (googleMap != null) {
UiSettings settings = googleMap.getUiSettings();
settings.setZoomControlsEnabled(true);
settings.setCompassEnabled(true);
settings.setTiltGesturesEnabled(false);
settings.setMyLocationButtonEnabled(true);
}
}
注意:
SupportMapFragment mMap;
GoogleMap googleMap;
希望对你有所帮助。