Jai
Jai

Reputation: 486

How to draw the map my current location to particular latitude longitude values

I create the Google Map using android i get my current location latitude longitude values and using some other latitude longitude value.Now how to draw the shortest path line in 2 location. My Main Activity.java:

public class MainActivity extends Activity {
GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    LatLng latLng = new LatLng(13.0847992, 80.2125527);
    map.addMarker(new MarkerOptions().position(latLng).title("Anna Nagar"));

    map.setMyLocationEnabled(true);
    map.getUiSettings().setZoomControlsEnabled(true);
    map.getUiSettings().setCompassEnabled(true);
    map.getUiSettings().setMyLocationButtonEnabled(true);
    map.getUiSettings().setAllGesturesEnabled(true);
    map.setTrafficEnabled(true);

}
}

Upvotes: 3

Views: 1310

Answers (1)

Jigar Shekh
Jigar Shekh

Reputation: 2810

Draw a path between your location to another location used MapNavigator library. It easy to used.

eg.

LatLng startLocation = new LatLng(start_lat, start_long);
LatLng endLocation = new LatLng(end_lat, end_long);

map.addMarker(new MarkerOptions().position(startLocation ).title("start"));
map.addMarker(new MarkerOptions().position(endLocation ).title("end"));

Navigator navigator = new Navigator(map, startLocation, endLocation);
navigator.findDirections(true);

Upvotes: 1

Related Questions