1

我想在地图上显示我的位置和目的地位置。问题是目标位置总是指向同一个位置,即使我改变另一个目的地很长很长......

这是代码

protected void tampilkanPosisikeMap(Location newLocation) {
    List<Overlay> overlays = mapView.getOverlays();

    if (overlays.size() > 0) {
        for (Iterator iterator = overlays.iterator(); iterator.hasNext();) {
            iterator.next();
            iterator.remove();
        }
    }

    GeoPoint geopoint = new GeoPoint(
            (int) (newLocation.getLatitude() * 1E6), (int) (newLocation
                    .getLongitude() * 1E6));
    GeoPoint myposition = geopoint;
    Location locationA = new Location("point A");
    Location locationB = new Location("point B");
    locationA.setLatitude(geopoint.getLatitudeE6() / 1E6);
    locationA.setLongitude(geopoint.getLongitudeE6() / 1E6);

    Drawable icon1 = getResources().getDrawable(R.drawable.user);
    icon1.setBounds(0, 0, icon1.getIntrinsicWidth(), icon1
            .getIntrinsicHeight());

    MyItemizedOverlay overlay1 = new MyItemizedOverlay(icon1, this);
    OverlayItem item1 = new OverlayItem(geopoint, "Posisi Anda", "Lat:"
            + locationA.getLatitude() + "\nLng:" + locationA.getLongitude());
    overlay1.addItem(item1);
    mapView.getOverlays().add(overlay1); 



    String lat2,longi2;
    String nama_rs;String alamat_rs;
    nama_rs = getIntent().getExtras().getString("namarsakit");
    alamat_rs = getIntent().getExtras().getString("alamatrsakit");
    lat2 = getIntent().getExtras().getString("lat");
    longi2 = getIntent().getExtras().getString("longi");
    Double lintang_rs = Double.parseDouble(lat2);
    Double bujur_rs = Double.parseDouble(longi2);

        GeoPoint geopoint1 = new GeoPoint(
                (int) (lintang_rs * 1E6),
                (int) (bujur_rs * 1E6));
        locationB.setLatitude(geopoint1.getLatitudeE6() / 1E6);
        locationB.setLongitude(geopoint1.getLongitudeE6() / 1E6);

        DecimalFormat formatData = new DecimalFormat("#.#");
        float distance = (float) locationA.distanceTo(locationB) / 1000;
        String jarak;
        jarak = String.valueOf(formatData.format(distance));

        Drawable icon = getResources().getDrawable(R.drawable.marker); //
        icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
                .getIntrinsicHeight());
        MyItemizedOverlay overlay = new MyItemizedOverlay(icon, this); //
        OverlayItem item = new OverlayItem(geopoint1, nama_rs,          //
                alamat_rs
                        + "\n\nJarak dari Posisi Anda : " + jarak + " km");
        overlay.addItem(item);
        mapView.getOverlays().add(overlay);
        Toast.makeText(MapDetailActivity.this,"nama = "+nama_rs+"lat tujuan= "+lintang_rs+"long tujuan = "+bujur_rs, Toast.LENGTH_SHORT).show();



    mapView.getController().animateTo(geopoint1);


}

这是上面的目标代码:

String lat2,longi2;
    String nama_rs;String alamat_rs;
    nama_rs = getIntent().getExtras().getString("namarsakit");
    alamat_rs = getIntent().getExtras().getString("alamatrsakit");
    lat2 = getIntent().getExtras().getString("lat");
    longi2 = getIntent().getExtras().getString("longi");
    Double lintang_rs = Double.parseDouble(lat2);
    Double bujur_rs = Double.parseDouble(longi2);

        GeoPoint geopoint1 = new GeoPoint(
                (int) (lintang_rs * 1E6),
                (int) (bujur_rs * 1E6));
        locationB.setLatitude(geopoint1.getLatitudeE6() / 1E6);
        locationB.setLongitude(geopoint1.getLongitudeE6() / 1E6);

        DecimalFormat formatData = new DecimalFormat("#.#");
        float distance = (float) locationA.distanceTo(locationB) / 1000;
        String jarak;
        jarak = String.valueOf(formatData.format(distance));

        Drawable icon = getResources().getDrawable(R.drawable.marker); //
        icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
                .getIntrinsicHeight());
        MyItemizedOverlay overlay = new MyItemizedOverlay(icon, this); //
        OverlayItem item = new OverlayItem(geopoint1, nama_rs,          //
                alamat_rs
                        + "\n\nJarak dari Posisi Anda : " + jarak + " km");
        overlay.addItem(item);
        mapView.getOverlays().add(overlay);
        Toast.makeText(MapDetailActivity.this,"nama = "+nama_rs+"lat tujuan= "+lintang_rs+"long tujuan = "+bujur_rs, Toast.LENGTH_SHORT).show();



    mapView.getController().animateTo(geopoint1);
4

1 回答 1

0

为了能够显示您的当前位置,您必须点击 GPS 位置提供商或网络位置提供商。查看您的代码,我看不到任何内容。请注意,模拟器上的 DDMS 将默认为特定位置。除非你自己提供

于 2013-03-19T08:08:39.983 回答