谷歌地图图块无法加载
我正在为 Android 开发一个简单的 Google 地图应用程序。我正在使用 Eclipse 和 Android 虚拟设备。运行应用程序时,没有显示图块,并且我收到消息“无法获取连接工厂客户端”。
我读过,看起来这是一个错误,但有些人说他们的应用程序可以正常工作。我尝试过在我的虚拟设备 (2.2) 上使用 API 1.6、2.1、2.2,但它们都不起作用。
我从 debug.keystore 获得的 MD5 中获取了 API 密钥。
我该如何解决这个问题?我刚刚找到了有同样问题的人,但有解决方案。
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uniovi.pfc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".SimpleMap2Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<user-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
</user-permission>
</manifest>
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0YSU8-p-YkHYQ2lit-vAsh2U0jW5zV3l_YQVlvw" />
</LinearLayout>
代码:
package uniovi.pfc;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
public class SimpleMap2Activity extends MapActivity {
private MapView mapView=null;
private MapController mapController=null;
private GeoPoint geoPoint=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview1);
mapController = mapView.getController();
String coordinates[] = { "40.747778", "-73.985556" };
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mapController.animateTo(geoPoint);
mapController.setZoom(5);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_I:
mapController.zoomIn();
break;
case KeyEvent.KEYCODE_O:
mapController.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
}
I'm developing a simple Google Maps app for Android. I'm using Eclipse and an Android Virtual Device. When running the app, no tiles are shown, and I get the message "Couldn't get connection factory client".
I've read and looks like it is a bug, but some people say they got their apps working. I've tried using API 1.6, 2.1, 2.2 over my virtual device (2.2) and none of them work.
I got my API key from the MD5 obtained from the debug.keystore.
How can I solve the problem? I just found people with the same problem, but any solutions.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uniovi.pfc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".SimpleMap2Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<user-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
</user-permission>
</manifest>
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0YSU8-p-YkHYQ2lit-vAsh2U0jW5zV3l_YQVlvw" />
</LinearLayout>
Code:
package uniovi.pfc;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
public class SimpleMap2Activity extends MapActivity {
private MapView mapView=null;
private MapController mapController=null;
private GeoPoint geoPoint=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview1);
mapController = mapView.getController();
String coordinates[] = { "40.747778", "-73.985556" };
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mapController.animateTo(geoPoint);
mapController.setZoom(5);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_I:
mapController.zoomIn();
break;
case KeyEvent.KEYCODE_O:
mapController.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,问题是地图 apiKey。这个话题在互联网上没有得到很好的解释。
简而言之,我将解释如下:
Finally, the problem was the maps apiKey. This topic is not very well explained over the internet.
Shortly, I would explain as following: