【发布时间】:2014-03-14 03:04:17
【问题描述】:
我正在尝试在我的模拟器上的子片段中显示 Google 地图。但问题是,当像这样加载地图时,模拟器会随着 toast 的持续显示而冻结:
我检查了我的清单文件,重新创建了 API 密钥和 debug.keystore。但它仍然无法正常工作。请告诉我如何解决这个问题。谢谢。
**注意:** 我正在 Genymotion 模拟器 - Galaxy S2 API 10(2.3.7) 上进行测试。 Google play 服务已安装在模拟器上。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.estytic.clubinthechi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<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.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.project.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.project.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:hardwareAccelerated="false"
android:logo="@drawable/ic_drawer1"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="api-key"/>
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.project.MainActivity"
android:label="@string/app_name"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/Theme.AppCompat" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MapFragment.java
public class MapFragmentClass extends Fragment implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener {
//to extract current loc
private LocationClient locationclient;
private LocationRequest locationrequest;
SupportMapFragment mapFragment;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_fragment, null);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
FragmentManager fm = getChildFragmentManager();
mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (mapFragment == null) {
mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, mapFragment).commit();
fm.executePendingTransactions();
delayMapLoading();
}
}
void delayMapLoading()
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
map = mapFragment.getMap();
if(map != null)
{
Log.i("MSG","map is not null");
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
else {
// handler.postDelayed(this, 500);
}
}
}, 1000);
}
map_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.03"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
【问题讨论】:
标签: android google-maps genymotion