Note that there are some explanatory texts on larger screens.

plurals
  1. POHow get direction between two point on google map in android?
    primarykey
    data
    text
    <p>I searched for two hours but only found draw Line, i want get direction as this form Click <a href="http://macoymejia.files.wordpress.com/2011/11/wpid-cap201111170534-1.jpg?w=627%22" rel="nofollow">here</a>! I have ten point and when i click the point i want to show direction from my location to the point. My code look:</p> <pre><code>package de.vogella.android.locationapi.maps; import android.content.Context; import android.graphics.drawable.Drawable; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; import com.google.android.maps.OverlayItem; import com.google.android.maps.Projection; public class ShowMapActivity extends MapActivity { private MapController mapController; private MapView mapView; private LocationManager locationManager; private MyOverlays itemizedoverlay,itemizedoverlay_central; private MyLocationOverlay myLocationOverlay; private String nameOfOffice_AZ[]; private String addressOfOffice_AZ[]; private String phoneOfOffice_AZ[]; public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.main); // bind the layout to the activity // Configure the Map mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Projection projection = mapView.getProjection(); nameOfOffice_AZ= getResources().getStringArray(R.array.NamesOFObject_AZ); addressOfOffice_AZ = getResources().getStringArray(R.array.AddressOfOffice_AZ); phoneOfOffice_AZ = getResources().getStringArray(R.array.PhoneOfOffice_AZ); mapController = mapView.getController(); mapController.setZoom(16); // Zoon 1 is world view locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler()); myLocationOverlay = new MyLocationOverlay(this, mapView); mapView.getOverlays().add(myLocationOverlay); myLocationOverlay.runOnFirstFix(new Runnable() { public void run() { mapView.getController().animateTo(myLocationOverlay.getMyLocation()); } }); Drawable drawable = this.getResources().getDrawable(R.drawable.office_icon); Drawable drawable_central = this.getResources().getDrawable(R.drawable.central_office); itemizedoverlay = new MyOverlays(this, drawable); itemizedoverlay_central = new MyOverlays(this, drawable_central); createMarker(); } @Override protected boolean isRouteDisplayed() { return false; } public class GeoUpdateHandler implements LocationListener { @Override public void onLocationChanged(Location location) { int lat = (int) (location.getLatitude() * 1E6); int lng = (int) (location.getLongitude() * 1E6); GeoPoint point = new GeoPoint(lat, lng); createMarker(); mapController.animateTo(point); // mapController.setCenter(point); } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } private void createMarker() { //CENTRAL OFFICE GeoPoint p_central = new GeoPoint((int)(40.38292884084829 * 1e6),(int)(49.84223246574 * 1e6)); OverlayItem overlayitem = new OverlayItem(p_central, nameOfOffice_AZ[0] ,addressOfOffice_AZ[0]+"\n"+phoneOfOffice_AZ[0] ); itemizedoverlay_central.addOverlay(overlayitem); mapView.getOverlays().add(itemizedoverlay_central); //END CENTRALL OFFICE GeoPoint p = new GeoPoint((int)(40.376455916943236 * 1e6),(int)(49.84803676605224 * 1e6)); overlayitem = new OverlayItem(p, nameOfOffice_AZ[0] ,addressOfOffice_AZ[0]+"\n"+phoneOfOffice_AZ[0] ); itemizedoverlay.addOverlay(overlayitem); mapView.getOverlays().add(itemizedoverlay); } @Override protected void onResume() { super.onResume(); myLocationOverlay.enableMyLocation(); myLocationOverlay.enableCompass(); } @Override protected void onPause() { super.onPause(); myLocationOverlay.disableMyLocation(); myLocationOverlay.disableCompass(); } </code></pre> <p>} and MyOverlays.java</p> <pre><code>package de.vogella.android.locationapi.maps; import java.util.ArrayList; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.Toast; import com.google.android.maps.GeoPoint; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem; public class MyOverlays extends ItemizedOverlay&lt;OverlayItem&gt; { private static int maxNum = 5; private OverlayItem overlays[] = new OverlayItem[maxNum]; private int index = 0; private boolean full = false; private Context mContext; private OverlayItem previousoverlay; public MyOverlays(Context context, Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); this.mContext = context; } private ArrayList&lt; OverlayItem &gt; mOverlays = new ArrayList&lt; OverlayItem &gt;(); public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } public void name() { } @Override protected OverlayItem createItem(int i) { return mOverlays.get(i); } @Override public int size() { return mOverlays.size(); } @Override protected boolean onTap(int i) { //when you tap on the marker this will show the informations provided by you when you create in the //main class the OverlayItem OverlayItem item = mOverlays.get(i); AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); dialog.setInverseBackgroundForced(true); dialog.setTitle(item.getTitle()); dialog.setMessage(item.getSnippet()); dialog.setCancelable(true); dialog.setPositiveButton("Go To", new OkOnClickListener()); /// dialog.setNegativeButton("No, no", new CancelOnClickListener()); dialog.show(); // nese bax = new nese(); // bax.oldu(mContext); return true; } private final class CancelOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { Toast.makeText(mContext, "You clicked yes", Toast.LENGTH_LONG) .show(); } } private final class OkOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { //Toast.makeText(mContext, "You clicked no", Toast.LENGTH_LONG).show(); } } public class RoutePath extends MapActivity { /** Called when the activity is first created. */ MapView mapView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapview); double src_lat = 25.04202; // the testing source double src_long = 121.534761; double dest_lat = 25.05202; // the testing destination double dest_long = 121.554761; GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6), (int) (src_long * 1E6)); GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6), (int) (dest_long * 1E6)); DrawPath(srcGeoPoint, destGeoPoint, Color.GREEN, mapView); mapView.getController().animateTo(srcGeoPoint); mapView.getController().setZoom(15); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } private void DrawPath(GeoPoint src, GeoPoint dest, int color, MapView mMapView01) { // code in section 2.2 } } </code></pre> <p>} </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload