我想在地图上显示我的位置和目的地位置。问题是目标位置始终指向相同的位置,即使我更改另一个目的地长和拉...
这是代码
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);
答案 0 :(得分:0)
要让您能够显示当前位置,您必须点击GPS位置提供商或网络位置提供商。看看你的代码我看不到任何这个。请注意,仿真器DDMS将默认为特定位置。除非你自己提供