您的位置:首页 > 编程语言 > Go语言

使用Google Map API可能会遇到的问题汇总

2013-10-12 16:57 831 查看
今天在将 http://www.curious-creature.org/2011/02/22/source-code-for-android-3-0-animation-demo/
这个Demo想在手机上测试的时候,

遇到了几个问题,参考下面的blog中问题解决,保留一下,后面万一再用到。

-----------------------------------------------------------------------------------------------------------------------------------------

http://blog.csdn.net/harry_helei/article/details/7282848

       闲来没事,一直在鼓捣公司的开发板,突然有一天想把google地图给整进来,于是开始行动。整个过程归纳为以下几个步骤:

1、基于Google API新建一个名为GoogleMap的工程

       几个重要工程文件的内容如下:

       1)、布局文件main.xml

[html]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:orientation="vertical" >  
  
    <com.google.android.maps.MapView  
        android:id="@+id/map_view"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:clickable="true"  
        android:apiKey="0vcWNfFdVG-uJZSMXPL0BnGQGlBYAxTs3frQpfQ"  
        />  
  
</LinearLayout>  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<com.google.android.maps.MapView
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0vcWNfFdVG-uJZSMXPL0BnGQGlBYAxTs3frQpfQ"
/>

</LinearLayout>

这里有两个地方需要说明:

i、MapView:跟Android SDK中的其它View是一样的,不同的是SDK中没有包含这个View,位于Google另外提供的jar包中,这个jar包全名叫com.google.android.maps.jar。

ii、android.apiKey:这个需要到网上进行申请,后面有说明

     2)、AndroidManifest.xml文件

[html]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>  
<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    package="com.raycommtech.googlemap"  
    android:versionCode="1"  
    android:versionName="1.0" >  
  
    <uses-sdk android:minSdkVersion="10" />  
    <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"/>  
  
    <application  
        android:icon="@drawable/ic_launcher"  
        android:label="@string/app_name"  
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">  
        <uses-library android:name="com.google.android.maps"/>  
        <activity  
            android:label="@string/app_name"  
            android:name=".GoogleMapActivity" >  
            <intent-filter >  
                <action android:name="android.intent.action.MAIN" />  
  
                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </activity>  
    </application>  
  
</manifest>  

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.raycommtech.googlemap"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<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"/>

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<uses-library android:name="com.google.android.maps"/>
<activity
android:label="@string/app_name"
android:name=".GoogleMapActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

有三个地方需要说明

i、android:minSdkVersion默认是14,我板子上的系统是2.3.7,API的Level是10,因此要改成目标板系统的API Level,否则运行时报以下错误:

[html]
view plaincopyprint?

[2012-02-22 13:05:56 - GoogleMap] ERROR: Application requires API version 14. Device API version is 10 (Android 2.3.7).  
[2012-02-22 13:05:56 - GoogleMap] Launch canceled!  

[2012-02-22 13:05:56 - GoogleMap] ERROR: Application requires API version 14. Device API version is 10 (Android 2.3.7).
[2012-02-22 13:05:56 - GoogleMap] Launch canceled!


ii、需要添加三个uses-permission:INTERNET, ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION

iii、指示使用外部库:使用uses-library指示使用包含MapView的com.google.android.maps.jar库

      3)、GoogleMapActivity.java文件

[java]
view plaincopyprint?

package com.raycommtech.googlemap;  
  
import com.google.android.maps.MapActivity;  
import com.google.android.maps.MapView;  
  
import android.os.Bundle;  
  
public class GoogleMapActivity extends MapActivity {  
    private MapView mMapView = null;  
      
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
          
        setContentView(R.layout.main);  
                  
        mMapView = (MapView)findViewById(R.id.map_view);  
        mMapView.setSatellite(false);  
        mMapView.setTraffic(true);  
        mMapView.setBuiltInZoomControls(true);  
    }  
  
    @Override  
    protected boolean isRouteDisplayed() {  
  
        return false;  
    }     
}  

package com.raycommtech.googlemap;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.os.Bundle;

public class GoogleMapActivity extends MapActivity {
private MapView mMapView = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

mMapView = (MapView)findViewById(R.id.map_view);
mMapView.setSatellite(false);
mMapView.setTraffic(true);
mMapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {

return false;
}
}

2、apiKey的申请

       在ubuntu上执行以下命令:

[html]
view plaincopyprint?

$cd ~  
$keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android  

$cd ~
$keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android

终端上输出产生以下结果:

     androiddebugkey, Mar 3, 2011, PrivateKeyEntry,
     Certificate fingerprint (MD5): E0:D1:06:6F:BE:4D:33:1C:3F:E6:C2:9C:49:E8:2F:1A
将生成的MD5指纹输入连接里生成所需的apiKey添到MapView的android:apiKey中即可

3、程序在开发板上的部署及问题的解决

       直接运行程序,Eclipse的console直接报错如下:

[html]
view plaincopyprint?

[2012-02-22 13:06:32 - GoogleMap] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY  
[2012-02-22 13:06:32 - GoogleMap] Please check logcat output for more details.  
[2012-02-22 13:06:32 - GoogleMap] Launch canceled!  

[2012-02-22 13:06:32 - GoogleMap] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2012-02-22 13:06:32 - GoogleMap] Please check logcat output for more details.
[2012-02-22 13:06:32 - GoogleMap] Launch canceled!

通过adb logcat看详细错误如下;

[html]
view plaincopyprint?

D/PackageParser( 1068): Scanning package: /data/app/vmdl583239231.tmp  
D/PackageManager( 1068): Scanning package com.raycommtech.googlemap  
E/PackageManager( 1068): Package com.raycommtech.googlemap requires unavailable shared library com.google.android.maps; failing!  
W/PackageManager( 1068): Package couldn't be installed in /data/app/com.raycommtech.googlemap-1.apk  

D/PackageParser( 1068): Scanning package: /data/app/vmdl583239231.tmp
D/PackageManager( 1068): Scanning package com.raycommtech.googlemap
E/PackageManager( 1068): Package com.raycommtech.googlemap requires unavailable shared library com.google.android.maps; failing!
W/PackageManager( 1068): Package couldn't be installed in /data/app/com.raycommtech.googlemap-1.apk

错误提示很明显,板子上的系统中没有com.google.android.maps.jar这个共享库。到Android的SDK的add-onsq/addon-google_apis-google_inc_-14/libs/目录下找到maps.jar,并将其重新命令为com.google.android.maps.jar,通过以下命令push到系统中:

[html]
view plaincopyprint?

$adb remount  
$adb push com.google.android.maps.jar /system/framework/  

$adb remount
$adb push com.google.android.maps.jar /system/framework/

重新启动系统,并执行程序,还是报上面的错误,明显添加的库没起作用,google上查了下,发现需要写一个com.google.android.maps.xml的permissions文件,内容如下:

[html]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>  
<permissions>  
    <library name="com.google.android.maps"  
             file="/system/framework/com.google.android.maps.jar" />  
</permissions>  

<?xml version="1.0" encoding="utf-8"?>
<permissions>
<library name="com.google.android.maps"
file="/system/framework/com.google.android.maps.jar" />
</permissions>


执行以下命令,将com.google.android.maps.xml文件push到系统中:

[html]
view plaincopyprint?

$adb remount  
$adb push com.google.android.maps.jar /system/etc/permissions/  

$adb remount
$adb push com.google.android.maps.jar /system/etc/permissions/

重新启动系统,并执行程序,报以下错误:

[html]
view plaincopyprint?

E/AndroidRuntime( 1340): FATAL EXCEPTION: main  
E/AndroidRuntime( 1340): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.raycommtech.googlemap/com.raycommtech.googlemap.GoogleMapActivity}: java.lang.ClassNotFoundException: com.raycommtech.googlemap.GoogleMapActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.raycommtech.googlemap-2.apk]  
E/AndroidRuntime( 1340):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)  
E/AndroidRuntime( 1340):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)  
E/AndroidRuntime( 1340):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)  
E/AndroidRuntime( 1340):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)  
E/AndroidRuntime( 1340):    at android.os.Handler.dispatchMessage(Handler.java:99)  
E/AndroidRuntime( 1340):    at android.os.Looper.loop(Looper.java:130)  
E/AndroidRuntime( 1340):    at android.app.ActivityThread.main(ActivityThread.java:3683)  
E/AndroidRuntime( 1340):    at java.lang.reflect.Method.invokeNative(Native Method)  
E/AndroidRuntime( 1340):    at java.lang.reflect.Method.invoke(Method.java:507)  
E/AndroidRuntime( 1340):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)  
E/AndroidRuntime( 1340):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)  
E/AndroidRuntime( 1340):    at dalvik.system.NativeStart.main(Native Method)  
E/AndroidRuntime( 1340): Caused by: java.lang.ClassNotFoundException: com.raycommtech.googlemap.GoogleMapActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.raycommtech.googlemap-2.apk]  
E/AndroidRuntime( 1340):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)  
E/AndroidRuntime( 1340):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)  
E/AndroidRuntime( 1340):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)  
E/AndroidRuntime( 1340):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)  
E/AndroidRuntime( 1340):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)  
E/AndroidRuntime( 1340):    ... 11 more  
W/ActivityManager( 1065):   Force finishing activity com.raycommtech.googlemap/.GoogleMapActivity  

E/AndroidRuntime( 1340): FATAL EXCEPTION: main
E/AndroidRuntime( 1340): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.raycommtech.googlemap/com.raycommtech.googlemap.GoogleMapActivity}: java.lang.ClassNotFoundException: com.raycommtech.googlemap.GoogleMapActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.raycommtech.googlemap-2.apk]
E/AndroidRuntime( 1340): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
E/AndroidRuntime( 1340): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 1340): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 1340): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 1340): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1340): 	at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1340): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 1340): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1340): 	at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1340): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 1340): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 1340): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1340): Caused by: java.lang.ClassNotFoundException: com.raycommtech.googlemap.GoogleMapActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.raycommtech.googlemap-2.apk]
E/AndroidRuntime( 1340): 	at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
E/AndroidRuntime( 1340): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 1340): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 1340): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 1340): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
E/AndroidRuntime( 1340): 	... 11 more
W/ActivityManager( 1065):   Force finishing activity com.raycommtech.googlemap/.GoogleMapActivity


很明显,Android SDK中的maps不给力啊,木有所需要的MapActivity。于是只能到网上去搜索,还真下到所需要的文件,下载文件,并按照上面的步骤将com.google.android.maps.jar和com.google.android.maps.xml分别push到系统中,再次重启开发板,执行程序就OK啦,显示效果如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  google map Android