我试图让谷歌地图显示从用户当前位置到用户点按的叠加层的路线。 这是我的重叠代码
public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public AddItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public AddItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
if (event.getAction() == 1) {
GeoPoint geopoint = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
// latitude
double lat = geopoint.getLatitudeE6() / 1E6;
// longitude
double lon = geopoint.getLongitudeE6() / 1E6;
// Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show();
}
return false;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
final OverlayItem item = mapOverlays.get(0);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setPositiveButton("Arahkan", new OnClickListener() {
//arahkan atau direction
public void onClick(DialogInterface arg0, int arg1) {
// Getting intent data
Intent i = getIntent();
// Users current geo location
String user_latitude = i.getStringExtra("user_latitude");
String user_longitude = i.getStringExtra("user_longitude");
// Geopoint to place on map
//geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
// (int) (Double.parseDouble(user_longitude) * 1E6));
StringBuilder urlString = new StringBuilder();
String saddr = newLocation.getLatitude(user_latitude)+","+newLocation.getLongitude(user_longitude);
String daddr = (item.getPoint().getLatitudeE6()/1E6)+","+(item.getPoint().getLongitudeE6()/1E6);
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr="+saddr);
urlString.append("&daddr="+daddr);
Intent ii = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString.toString()));
context.startActivity(i);
}
private Intent getIntent() {
// TODO Auto-generated method stub
return null;
}
});
dialog.show();
return true;
}
private MapView findViewById(int mapview2) {
// TODO Auto-generated method stub
return null;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
}
public void populateNow(){
this.populate();
}
}
请给我你的意见,如果有人希望解决我的代码问题,我会很感激。 谢谢。 :)