@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); byte[] data = getIntent().getExtras().getByteArray(SHOW_ROUTE_EXTRA_PROTO); if (data == null) { Log.v(TAG, "Intent Data is null"); finish(); } try { route = Route.parseFrom(data); } catch (InvalidProtocolBufferException e) { Log.v(TAG, "Intent Data does not parse"); e.printStackTrace(); finish(); } storage = new PlaceStorage(this); // Ug, this is unfortunate. if (route.getRoutePointCount() == 0) { place = Place.newBuilder().setLatitude(0).setLongitude(0).build(); } else { place = storage.getPlaceForRoute(RouteUtils.getLastRoutePoint(route)); } setTitle(RouteCursorAdapter.getRouteTime(route)); setContentView(R.layout.activity_show_route_map); RouteCursorAdapter.setupListView(findViewById(R.id.routeDetails), route, storage, null); map = ((MapFragment) getFragmentManager().findFragmentById(R.id.bigMap)).getMap(); map.setMapType(GoogleMap.MAP_TYPE_NORMAL); Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(getBounds(), size.x, size.y, 50); map.moveCamera(cameraUpdate); showRoute(); }
private void showRoute() { PolylineOptions rectOptions = new PolylineOptions(); LatLng latLng = null; for (RoutePoint point : route.getRoutePointList()) { latLng = new LatLng(point.getLatitude(), point.getLongitude()); rectOptions.add(latLng); } rectOptions.color(0xA00080FF); map.addPolyline(rectOptions); MarkerOptions endMarker = new MarkerOptions(); endMarker.position(latLng); String label = place != null ? place.getName() : "Parking Spot"; endMarker.title(label + " @ " + RouteCursorAdapter.getRouteTimeAgo(this, route)); endMarker.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)); endMarker.anchor(0.5f, 0.5f); map.addMarker(endMarker); }