2014-07-13 36 views
0

我想在我的Android应用程序中嵌入谷歌地图,但API抛出“IOException异常:服务器返回:3”,类似这样的问题:Android Google Maps API throwing server returned 3与空网格产生java.io.IOException:返回服务器:3的Android谷歌地图

我试图按照这些提示:

  1. 使用谷歌地图API第2?是的,并按照此步骤:https://developers.google.com/maps/documentation/android/start

  2. 是APK签署?签名者与调试证书的是,就在这里生成API KEY:https://console.developers.google.com/和使用SHA1指纹蚀出(首选项 - > Android的 - >构建 - > SHA1指纹)

如果任何人都可以帮助,我会欣赏

我的AndroidManifest.xml:

  1. 我的权限和功能:

    <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" /> 
    <!-- Location --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    
    <!-- OpenGL for Google Maps --> 
    <uses-feature 
        android:glEsVersion="0x00020000" 
        android:required="true" /> 
    
  2. 有用的细节在 “应用程序” 标签:

    <application 
        android:allowBackup="true" 
        android:icon="@drawable/ic_iconlauncher" 
        android:label="@string/app_name" 
        android:theme="@style/customActionBarTheme" 
        android:hardwareAccelerated="true"> 
        <uses-library android:name="com.google.android.maps" /> 
    
        <meta-data 
         android:name="com.google.android.maps.v2.API_KEY" 
         android:value="@string/api_key_gmaps" /> 
        <meta-data 
         android:name="com.google.android.gms.version" 
         android:value="@integer/google_play_services_version" /> 
        [...] 
    </application> 
    

在我的布局定义:

<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/navigationBottom" 
    android:apiKey="@string/api_key_gmaps" 
    android:clickable="true" /> 

回答

0

的谷歌开发人员文件地图V2完全是误导性的......我挣扎整天让它工作。对我有效的是:

在你的布局文件中,而不是MapView元素,你应该使用一个片段元素,将“class”属性设置为“com.google.android.gms.SupportMapFragment”,如下所示: 请注意,我使用的,因为我的目标分钟API的支持库是8

<fragment 
class="com.google.android.gms.maps.SupportMapFragment" 
android:id="@+id/mapview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"/> 

在你的活动,你应该得到的地图实例首先得到使用fragmentManager的片段,然后浇铸对类你用,然后调用的GetMap():

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 



public class SelectLojaActivity extends FragmentActivity{ 

private GoogleMap map; 

@Override 
protected void onCreate(Bundle arg0) { 
    // TODO Auto-generated method stub 
    super.onCreate(arg0); 
    setContentView(R.layout.activity_select_loja); 

    map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapview)).getMap(); 

} 


} 

不要忘记在[您-Android的SDK文件夹] /演员/谷歌/ google_play_services/libproject /谷歌播放services_lib并在项目 - 它添加>属性 - > Android的导入谷歌播放,services_lib作为图书馆。

!!注意!!至少在我的情况中,我在添加google-play-services后遇到了一个非常恼人的问题,Eclipse在尝试编译项目时开始耗尽内存。为了解决这个问题,我编辑的eclipse.ini的eclipse文件夹内,并提高内存量,它使用:

的eclipse.ini

-startup 
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar 
--launcher.library 
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-144807 
-product 
com.android.ide.eclipse.adt.package.adtproduct 
-showsplash 
org.eclipse.platform 
--launcher.XXMaxPermSize 
256m 
--launcher.defaultAction 
openFile 
-vmargs 
-Dosgi.requiredJavaVersion=1.6 
-XX:MaxPermSize=256m 
-Xms256m 
-Xmx512m 

增加最后两个值类似-Xms512m和 - Xmx1024m,重新启动Eclipse,增加值,直到内存堆大小问题消失。 希望它可以帮助...

相关问题