好吧,大家好!
因此,从 Android Google Maps API v2 开发开始不太友好,我想我可以通过发布我的试用结果并获得一些反馈来获得一些智慧,希望你能够足够慷慨地给我一些指导.
所以,我们开始吧!
首先,我的 Activity 代码:
package com.example.ok;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
二,Manifest 的代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ok"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.ok.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.ok.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.gms.maps" />
<activity
android:name="com.example.ok.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I Got it and I had to change debug keystore for it and ... long story but I really think it's a good apikey" />
</application>
</manifest>
三、布局 XML 的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
所以你会注意到,对于初学者来说,只不过是一个标准代码,可以开始学习更多更深入的东西......但是,它还是行不通!
现在,完成我的研究后,我必须评估一些导致我困难的最终原因,这就是我所经历的:
1- 模拟器通常不会处理这个问题,因为这些虚拟机还没有很好地支持 openGL es 2.0,所以情况就是这样,
2- apiKey 不好,实际上一开始尝试使用 api v1 编写代码,因此我遇到了各种问题(已弃用..),我现在转向使用 v2 编写代码,我已经删除了调试keystore 文件,然后在 eclipse 上重建,得到一个新的,然后使用带有包名的 SHA-1 代码在 Google 控制台上生成新的 apiKey 代码......所以我不认为这对我来说是邪恶的根源,
3-尝试了一个设备,我已经下载了几个 openGL es 2.0 的演示,它运行良好,所以一定不是 openGL(但谁知道?)。当我尝试安装apk时,它声明应用程序必须有权使用internat和位置数据等,我点击安装但是......对不起,“应用程序未安装”!
4- 我在我的项目库中引入了必要的东西,意思是:android-support-v4.jar 和 google-play-services.jar 等等......
5-确保项目构建目标是google apis 17(与4.2平台兼容,在写这篇文章时我注意到我的设备是4.0.2 Android版本,可能是这样吗?)。
所以,这很长,希望你仍然可以在你身上找到它,以表明任何潜在的解决方案可能对我有用。
提前致谢 !
在这里,我添加了我的 logcat 的最后(和重复的部分),只出现了错误:
04-11 17:11:15.289: E/StrictMode(700): null
04-11 17:11:15.289: E/StrictMode(700): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d195d0 that was originally bound here
04-11 17:11:15.289: E/StrictMode(700): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 17:11:15.289: E/StrictMode(700): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 17:11:15.289: E/StrictMode(700): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 17:11:15.289: E/StrictMode(700): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 17:11:15.289: E/StrictMode(700): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-11 17:11:15.289: E/StrictMode(700): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 17:11:15.289: E/StrictMode(700): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 17:11:15.289: E/StrictMode(700): at java.lang.Thread.run(Thread.java:856)