0

住所があり、その住所を Google マップに表示したい。地図は表示されていますが、その特定の住所を指していません。これが私のコードです。次のエラーが表示されます: couldn't get connection factory client

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);
4

2 に答える 2

1

私はあなたがアンドロイドマニフェストで以下の許可を提供したと仮定します
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

テストデバイスでGPSをアクティブにする必要があります。エミュレーターでテストし、エミュレーターがアクティブ化されていない場合、を使用しようとすると「null」になりますLocationManager

GoogleマップアクティビティはエミュレータでGPSデバイスを自動的にアクティブ化する必要がありますが、ロケーションマネージャを直接使用する場合は、自分でこれを行う必要があります。 GPSを使用して位置を設定すると便利です。

于 2012-12-07T04:31:54.940 に答える