2012-06-01 174 views
0

我有一个地址,并希望在Google地图上显示该地址。地图正在显示,但并未指向该特定地址。这是我的代码。我得到这个错误:couldn't get connection factory client不在Google地图上显示位置

private MapController mc; 
private MapView mapView; 
GeoPoint p; 
private MyOverlays mapOverlay; 
mapView = (MapView) findViewById(R.id.myMapView); 
mapView.setBuiltInZoomControls(true); 
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); 
    try { 
    List<Address> addresses = geoCoder.getFromLocationName(loc, 5); 
    if (addresses.size() > 0) { 
     p = new GeoPoint(
     (int) (addresses.get(0).getLatitude() * 1E6), 
     (int) (addresses.get(0).getLongitude() * 1E6)); 
     mc.animateTo(p); 
     mapView.invalidate(); 
    } 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
    if (p != null) { 
    Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher); 
    mapOverlay = new MyOverlays(drawable, this); 
    OverlayItem overlayitem = new OverlayItem(p, "", ""); 
    mapOverlay.addOverlay(overlayitem); 
    mapView.getOverlays().add(mapOverlay); 
    this.mc = this.mapView.getController(); 
    this.mc.setCenter(this.p); 
    this.mc.setZoom(16); 
    } 
    // LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    // lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, (LocationListener) this); 

回答

0

你应该在设备上测试你的代码而不是模拟器。

不知道为什么,但模拟器中存在一些问题。

在我的情况下,它在设备上正常工作,但在模拟器上给出相同的错误。

+0

嗨thx 4回复..我在设备上测试..但它给力关闭错误.. – ZooZoo

+0

哪个例外? [见日志猫] – Mufazzal

+0

06-01 13:26:56.004:E/MapActivity(305):无法获得连接工厂客户端 – ZooZoo

1

我假设你已经在Android的提供以下权限清单
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

您需要激活您的测试设备上的GPS。如果您在模拟器上进行测试并且未激活,则如果您尝试使用LocationManager,则会得到“null”。

Google地图活动应自动激活模拟器中的GPS设备,但如果您想直接使用位置管理器,则需要自己执行此操作。 Using GPS and setting location会帮助你。