Reputation: 1405
I want to create a Map activity (FragmentActivity) that displays a Google Map and shows navigation between 2 points.
I have one made that shows one location but I've no idea on how to create navigation to another point, every link I saw gives their web api as the solution (https://maps.google.com/maps?saddr=X,Y&daddr=X,Y)
and I want to do exactly what it does just programmatically through the activity and not just link into their webpage
my code so far:
try{
bndl = getIntent().getExtras();
COORDS = new LatLng(bndl.getDouble("lat"), bndl.getDouble("long"));
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (map != null) {
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.addMarker(new MarkerOptions().position(COORDS).title("Your parking spot!"));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(COORDS)
.zoom(20)
.bearing(90)
.tilt(0)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
}
catch (Exception e){
Log.v("except", ""+e);
}
now this only shows the one location (as it should do) but how to create another marker or something to navitage to? Is there a way to do this or do I HAVE to use their web api?
Upvotes: 0
Views: 2191
Reputation: 41099
Well, you could use this blog post guide I wrote on this topic:
Google Maps API V2: Navigation using Polyline
There is a source project there with the implementation that you can use to achieve exactly what you want.
Upvotes: 2