package com.netvariant.zain.activity; public class StoreMapActivity extends SherlockFragmentActivity { private GoogleMap googleMap; String longitude="0"; String latitude="0"; String title=""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); Bundle extras = getIntent().getExtras(); longitude = extras.getString("longitude"); latitude = extras.getString("lattitude"); title= extras.getString("name"); try { // Loading map initilizeMap(); } catch (Exception e) { e.printStackTrace(); } } private void initilizeMap() { if (googleMap == null) { double savedLat = Double.parseDouble(latitude); double savedLng =Double.parseDouble(longitude); LatLng cameraLatLng = new LatLng(savedLat, savedLng); googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById( R.id.map)).getMap(); googleMap.addMarker(new MarkerOptions() .position(new LatLng( Float.parseFloat(latitude), Float.parseFloat(longitude))).title("Marker") .title(title)); googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, 17)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } } protected void onResume() { super.onResume(); initilizeMap(); } }
这是我的地图类,在samsung s4 4.2.2上它崩溃了。我使用google play services froyo。 布局很简单,它是一个片段。不幸的是,我自己没有能够检测到发生了什么。有人试图在s4上报告它崩溃了。任何帮助都会很感激。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <fragment android:id="@+id/map" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
我的清单文件,希望有帮助.....
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<application
android:name="com.netvariant.zain.android.ZainApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.netvariant.zain.activity.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="com.netvariant.zain.activity.RegionalStoresActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.RegionalStoresMeActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.UsageActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.StoresActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PackagePlanActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CategoriesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoadingActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoginActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.LoginAuthenticationActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.SlidingMenuActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CategoriesNewsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ArticlesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ArticlesNewsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.StoreMapActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PostPaidMenuVoiceActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PrePaidMenuVoiceActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PrePaidMenuDataActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.PostPaidMenuDataActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.BillsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.ExtrasActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.BillsAmountActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.netvariant.zain.activity.CallDetailsInnerActivity"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD6geBmLw7N6gkDy1zCg7Y4yMtf_QnAOMs" />
</application>
答案 0 :(得分:1)
添加以下内容,
< meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" >
< /meta-data>
位于第一个元数据标记(您已放置Google API密钥的位置)正下方的清单文件中