I have two activities one that send coordinates and one that recieves and drawing them.
I need that both of them will show GoogleMap... in the first activity i can see google map right away but then when i call to the second activity from BroadcastReceiver i just see blank white screen.
Thats my Second activity code:
public class NewActivity extends FragmentActivity {
GoogleMap googleMap;
String message;
String number;
double[] d = new double[4];
ArrayList<LatLng> points= new ArrayList<LatLng>() ;
#Override
public void onStart() {
super.onStart();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
final IntentFilter localFilter = new IntentFilter();
localBroadcastManager.registerReceiver(localBroadcastReceiver, localFilter);
}
#Override
public void onStop() {
super.onStop();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
// Make sure to unregister!!
localBroadcastManager.unregisterReceiver(localBroadcastReceiver);
}
BroadcastReceiver localBroadcastReceiver = new BroadcastReceiver()
{
#Override
public void onReceive(Context context, Intent intent)
{
setContentView(R.layout.ye);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
message=intent.getStringExtra("message");
number=intent.getStringExtra("number");
int p=0;
Matcher m = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(message);
while(m.find())
{
double k = Double.parseDouble(m.group(1));
d[p]=k;
p++;
}
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.BLUE);
// Setting the width of the polyline
polylineOptions.width(6);
// Adding the taped point to the ArrayList
LatLng coordlocation = new LatLng(d[0], d[1]);
points.add(coordlocation);
LatLng coordlocation2 = new LatLng(d[2], d[3]);
points.add(coordlocation2);
// Setting points of polyline
polylineOptions.addAll(points);
googleMap.addPolyline(polylineOptions);
}
};
}
Note : I didnt registered the localBroadcastReceiver in the manifest file since i dont know if its neccessary.
I solved it by adding this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ye);
}
Related
I'm making an app in which I'm using GoogleMaps.Now, I have a question about communication between MapActivity and ToursActivity.To simplify it, my app is about band Metallica, and I have list of Tours. When user clicks on one of the Tours, it should open a new Activity with that location. I won't put ToursActivity here, cause there is a bunch of code that you don't need.Also, I'm keeping all my data on Firebase, if that's important.
This is my MapActivity:
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final int REQUEST_LOCATION_PERMISSION = 10;
private GoogleMap.OnMapClickListener mCustomOnMapClickListener;
private GoogleMap mGoogleMap;
private MapFragment mMapFragment;
#BindView(R.id.lvTours) ListView lvTours;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tours_coord);
this.initialize();
lvTours.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
public void initialize(){
this.mMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fGoogleMap);
this.mMapFragment.getMapAsync(this);
this.mCustomOnMapClickListener = new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
MarkerOptions newMarkerOptions = new MarkerOptions();
newMarkerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.tour));
newMarkerOptions.title("Tour");
newMarkerOptions.snippet("It' was here!");
newMarkerOptions.position(latLng);
mGoogleMap.addMarker(newMarkerOptions);
}
};
}
#Override
public void onMapReady(GoogleMap googleMap) {
this.mGoogleMap = googleMap;
UiSettings uiSettings = this.mGoogleMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
uiSettings.setMyLocationButtonEnabled(true);
uiSettings.setZoomGesturesEnabled(true);
this.mGoogleMap.setOnMapClickListener(this.mCustomOnMapClickListener);
goToLocation(33.835293 , -117.914505);
}
public void goToLocation(double lat, double lng){
LatLng latLng = new LatLng(lat, lng);
CameraPosition position = CameraPosition.builder()
.target(latLng)
.zoom(16f)
.bearing(0.0f)
.tilt(0.0f)
.build();
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(position),null);
}
private boolean hasLocationPermission() {
String LocationPermission = android.Manifest.permission.ACCESS_FINE_LOCATION;
int status = ContextCompat.checkSelfPermission(this, LocationPermission);
if (status == PackageManager.PERMISSION_GRANTED) {
this.mGoogleMap.setMyLocationEnabled(true);
return true;
}
return false;
}
private void requestPermission() {
String[] permission = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
ActivityCompat.requestPermissions(MapActivity.this, permission, REQUEST_LOCATION_PERMISSION);
}
}
You can use Intent with extra parameters.
For example, on ToursActivity.java
Intent intent = new Intent(ToursActivity.this, MapActivity.class);
intent.putExtra("lat", latitude);
intent.putExtra("long", longitude);
startActivity(intent);
Then you can get get these parameters on onCreate() method of MapActivity.java:
Intent intent = getIntent();
long latitude = intent.getLongExtra("lat", 0);
long longitutde = intent.getLongExtra("long", 0);
You can use intent with extra parameters.
Intent intent = new Intent(ToursActivity.this, MapActivity.class);
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
startActivity(intent);
Then you can get your values in onCreate() method of MapActivity.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
double latitude = intent.getDouble("latitude");
double longitude = intent.getDouble("longitude");
I have a button in this view which also has map class but somehow I cant set a listener to this button:
fileBtn.setOnClickListener(this);
I am not sure this is because this is a map class/fragment or any other reason.
The full class here:
/**
* This shows how to listen to some {#link GoogleMap} events.
*/
public class MapsActivity extends AppCompatActivity
implements OnMapClickListener, OnMapLongClickListener,
OnMapReadyCallback, OnClickListener {
private TextView mTapTextView;
private Button fileBtn;
private static final int REQUEST_PICK_FILE = 1;
private File selectedFile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mTapTextView = (TextView) findViewById(R.id.tap_text);
mTapTextView.setText("Loaded");
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(map);
mapFragment.getMapAsync(this);
}
Button fileBtn = (Button) findViewById(R.id.loadfile);
fileBtn.setOnClickListener(this);
public void onClick(View v) {
switch(v.getId()) {
case R.id.loadfile:
Intent intent = new Intent(this, FilePicker.class);
startActivityForResult(intent, REQUEST_PICK_FILE);
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
switch(requestCode) {
case REQUEST_PICK_FILE:
if(data.hasExtra(FilePicker.EXTRA_FILE_PATH)) {
selectedFile = new File
(data.getStringExtra(FilePicker.EXTRA_FILE_PATH));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "Test single attachment");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"amirfarazmand#gmail.com"});
intent.putExtra(Intent.EXTRA_TEXT, "Mail with an attachment");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH))));
intent.setType("application/pdf");
startActivity(Intent.createChooser(intent, "Send mail"));
}
break;
}
}
}
private GoogleMap googleMap;
#Override
public void onMapReady(GoogleMap map) {
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(this);
googleMap = map;
enableMyLocation();
}
/* private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995);
private static final LatLng PERTH = new LatLng(-31.95285, 115.85734); */
public int i=0;
public Polygon polygon;
public Polyline polyline;
List<LatLng> coordinates=new ArrayList<LatLng>();
public void onMapClick(LatLng point) {
mTapTextView.setText("tapped, point=" + point);
if (i==0){
i=1;
coordinates.add(point);
googleMap.addMarker(new MarkerOptions()
.position(point)
.title(String.valueOf(point.latitude))
.snippet(String.valueOf(point.latitude))
.rotation((float) -15.0)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
);
} else if (i==1) {
i=i+1;
coordinates.add(point);
polyline = googleMap.addPolyline((new PolylineOptions())
.add(coordinates.get(0), coordinates.get(1)));
}else if (i>1){
coordinates.add(point);
polyline.remove();
if (i>2){polygon.remove();};
polygon = googleMap.addPolygon(new PolygonOptions()
.addAll(coordinates)
.strokeColor(Color.BLACK)
.strokeWidth(10));
//polygon = googleMap.addPolygon((new PolygonOptions())
// .add(coordinates.get(0), coordinates.get(1),coordinates.get(2)));
i=i+1;
}/*else{
List<LatLng> polygonList = polygon.getPoints();
Toast.makeText(getBaseContext(), polygonList.toString(), Toast.LENGTH_LONG).show();
polygonList.add(point);
polygon.remove();
polygon = googleMap.addPolygon((new PolygonOptions()));
polygon.setPoints(polygonList);
i=i+1;
}*/
}
public boolean mapView = true;
#Override
public void onMapLongClick(LatLng point) {
if(mapView) {
mTapTextView.setText("long pressed, point=" + point);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mapView=!mapView;
}else{
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mapView=!mapView;
}
}
//Load coorodinates from file
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private void enableMyLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission to access the location is missing.
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (googleMap != null) {
// Access to the location has been granted to the app.
googleMap.setMyLocationEnabled(true);
googleMap.setTrafficEnabled(true);
}
}
/**
* Displays a dialog with error message explaining that the location permission is missing.
*/
private void showMissingPermissionError() {
PermissionUtils.PermissionDeniedDialog
.newInstance(true).show(getSupportFragmentManager(), "dialog");
}
}
I think you need to declare button and click listner in onCreate() method rather than outside
of it.Like:
oncreate()
{
b1=(Button)findviewbyId(R.id.abc);
b1.setOnclicklistener(this);
}
when You implement View.Onclicklistener...You will get override method onClick
....Inside that based on id you implement your logic.
You should add listener inside onCreate. Then override method for onClick.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mTapTextView = (TextView) findViewById(R.id.tap_text);
mTapTextView.setText("Loaded");
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(map);
mapFragment.getMapAsync(this);
Button fileBtn = (Button) findViewById(R.id.loadfile);
fileBtn.setOnClickListener(this);
}
Override method.
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.loadfile:
Intent intent = new Intent(this, FilePicker.class);
startActivityForResult(intent, REQUEST_PICK_FILE);
break;
}
}
Why these line
Button fileBtn = (Button) findViewById(R.id.loadfile);
fileBtn.setOnClickListener(this);
are outside onCreate() method ?
The Reason is that because ur Class implements OnClickListener instead of View.OnClickListener
Button fileBtn = (Button) findViewById(R.id.loadfile);
fileBtn.setOnClickListener(this);
Your code is dizzy, what I understood is you need to put this code inside onCreate.
i'm developing my first app and i created the following map viewer activity:
public class MapViewer extends Activity implements OnInfoWindowClickListener, ClusterManager.OnClusterClickListener<MyItem> {
private GoogleMap map;
private LatLng defaultLatLng = new LatLng(X, Y);
private int zoomLevel = 5;
private Database db = new Database(this);
private ClusterManager<MyItem> mClusterManager;
private LatLngBounds allowedBounds;
private final LatLng northeast = new LatLng(A, B);
private final LatLng southwest = new LatLng(C, D);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapviewer);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(northeast);
builder.include(southwest);
allowedBounds = builder.build();
try {
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if (map != null) {
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setRotateGesturesEnabled(false);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, zoomLevel));
mClusterManager = new ClusterManager<MyItem>(this, map);
mClusterManager.setRenderer(new MyClusterRenderer(this, map, mClusterManager));
mClusterManager.setOnClusterClickListener(this);
map.setOnCameraChangeListener(mClusterManager);
map.setOnMarkerClickListener(mClusterManager);
map.setInfoWindowAdapter(new ClusterInfoWindow(getLayoutInflater()));
map.setOnInfoWindowClickListener(this);
addItems();
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
As you can see i set a listener to map object
map.setOnCameraChangeListener(mClusterManager);
that adds or removes clusters on markers groups, according to zoom level.
Now i would add a listener that checks if user moves on map within some bounds:
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
checkBounds();
}
});
But it doesn't work. It works only if i remove the previous listener (mClusterManager).
So, how to make both listener working on the same map object?
Thank you in advance for your replies and sorry for my english.
As there's only a set method and no add method, you can only set one listener at a time. But you could delegate from the one listener to the other like this:
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
checkBounds();
mClusterManager.onCameraChange(cameraPosition);
}
});
Of course mClusterManager does not need to implement the CameraChangeListener interface any more but just needs a method public void onCameraChange(CameraPosition cameraPosition).
I have a GridMarkerClusterer with some Marker in it representing shared bike stations. I want those markers have a custom MarkerInfoWindow (bubble) with a click listener so that when the user clicks on the bubble, a new intent is launched.
Thus far, I'm OK.
Now I want to put extra data (station information corresponding to the marker) to that intent.
What I actually did is to add a constructor in my StationMarkerInfoWindow which takes a Station in parameter. I then add this parameter to the intent with putExtra() in my OnClickListener.
That's working but what is wrong is that I need to create a new StationMarkerInfoWindow for each marker instead of using the same object, and if I have more than 1000 markers to display, the activity takes up to 10 seconds to be created on my device (~1 second if I use the same StationMarkerInfoWindow object for each marker).
The question is: how should I add those data to the intent?
Here are the relevant parts of the code:
public class MapActivity extends Activity {
private BikeNetwork bikeNetwork;
private ArrayList<Station> stations;
private MapView map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// ...
stations = bikeNetwork.getStations();
map = (MapView) findViewById(R.id.mapView);
GridMarkerClusterer stationsMarkers = new GridMarkerClusterer(this);
Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
map.getOverlays().add(stationsMarkers);
stationsMarkers.setIcon(clusterIcon);
stationsMarkers.setGridSize(100);
for (final Station station : stations) {
stationsMarkers.add(createStationMarker(station));
}
// ...
}
private Marker createStationMarker(Station station) {
Marker marker = new Marker(map);
marker.setInfoWindow(new StationMarkerInfoWindow(
R.layout.bonuspack_bubble, map, station)); // this seems wrong
marker.setInfoWindow(stationMarkerInfoWindow);
marker.setPosition(stationLocation);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
marker.setIcon(getResources().getDrawable(R.drawable.ic_bike));
marker.setTitle(station.getName());
marker.setSnippet(String.valueOf(station.getFreeBikes())); // free bikes
marker.setSubDescription(String.valueOf(station.getEmptySlots())); // empty slots
return marker;
}
private class StationMarkerInfoWindow extends MarkerInfoWindow {
Station station;
public StationMarkerInfoWindow(int layoutResId, final MapView mapView, final Station station) {
super(layoutResId, mapView);
this.station = station;
}
#Override
public void onOpen(Object item) {
super.onOpen(item);
closeAllInfoWindowsOn(map);
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.map_bubble_layout);
layout.setClickable(true);
layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MapActivity.this, StationActivity.class);
intent.putExtra("station", station);
startActivity(intent);
}
});
}
}
}
I would suggest to set the Station as the "related object" of its Marker:
marker.setRelatedObject(station);
You can then retrieve this related object in StationMarkerInfoWindow#onOpen:
Marker marker = (Marker)item;
selectedStation = (Station)marker.getRelatedObject();
Similar implementation can be found here.
Then you can share the same StationMarkerInfoWindow.
I have a GoogleMap which displays fine (within a SupportMapFragment) and uses the GoogleMapOptions for the target camera location. However, I am unable to add markers/polylines to the GoogleMap. Here is the method for creating the map:
private void createMap(List<LatLng> latLngs) {
if(map == null) {
GoogleMapOptions options = new GoogleMapOptions();
mapFragment = SupportMapFragment.newInstance(options);
map = mapFragment.getMap();
float zoom = 13;
CameraPosition cameraP = new CameraPosition(latLngs.get(0), zoom, 0, 0);
options.camera(cameraP);
//TODO MAP IS NULL - SORT OUT!
// check it has been instantiated
if (map != null) {
Log.d(TAG, "map is not null");
map.clear();
//Calculate target zoom, based on trip size
map.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraP));
// Add LatLngs to polyline
PolylineOptions poly = new PolylineOptions().color(Color.RED);
MarkerOptions startMarker = new MarkerOptions()
.position(latLngs.get(0)).title("Start");
MarkerOptions endMarker = null;
if(latLngs.size() > 1) {
endMarker = new MarkerOptions().position(
latLngs.get(latLngs.size() - 1)).title("End");
}
for (LatLng latLng : latLngs) {
poly.add(latLng);
}
map.addPolyline(poly);
map.addMarker(startMarker);
map.addMarker(endMarker);
}
ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.trip_summary_map_container, mapFragment);
ft.commit();
}
}
As you can see from the inline comments, the map is still null (although it is displaying and using the options). Just can't add things to it. I assume I am not instantiating it properly?
The Activity extends FragmentActivity, and I have set up all the necessary stuff for using the Maps API.
Thank you for any help.
EDIT: I have posted a new answer with the solution I prefer to use now.
I had the same problem some days ago and I solved it extending SupportMapFragment class so that it executes a callback method once the map is finally ready.
public class ExtendedSupportMapFragment extends SupportMapFragment {
public static interface MapReadyListener {
public void mapIsReady(GoogleMap map);
}
#Deprecated
public static SupportMapFragment newInstance() {
return null;
}
#Deprecated
public static SupportMapFragment newInstance(GoogleMapOptions options) {
return null;
}
public static ExtendedSupportMapFragment newInstance(MapReadyListener mapReadyListener) {
ExtendedSupportMapFragment fragment = new ExtendedSupportMapFragment();
fragment.mapReadyListener = mapReadyListener;
return fragment;
}
private MapReadyListener mapReadyListener;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mapReadyListener != null)
mapReadyListener.mapIsReady(getMap());
}
}
Then you just need to do something like this:
public class RutaMapaFragment extends SherlockFragment implements ExtendedSupportMapFragment.MapReadyListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentMapa = ExtendedSupportMapFragment.newInstance(RutaMapaFragment.this);
}
...
#Override
public void mapIsReady(GoogleMap map) {
//Do whatever you want with your map.
}
}
So, time has passed and all. The fact is that I don't use the solution in my previous answer anymore, but prefer to use a ViewTreeObserver instead. The following code shows a rather simple fragment with a SupportMapFragment being added to it.
The method createMap() adds the SupportMapFragment and then executes setupMap(), but only via a OnGlobalLayoutListener that will basically be executed once the map is actually ready. Of course, this listener is removed immediately—there's no need to keep it there any longer.
public class MyMapFragment extends Fragment {
private View mMapContainer;
private SupportMapFragment mMapFragment;
private GoogleMap mMap;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(/* ... */);
// ...
mMapContainer = view.findViewById(R.id.map_fragment_container);
createMap();
return view;
}
private void createMap() {
mMapFragment = new SupportMapFragment();
getFragmentManager().beginTransaction()
.replace(R.id.map_fragment_container, mMapFragment)
.commit();
mMapContainer.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
mMapContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mMapContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
mMap = mMapFragment.getMap();
setupMap();
}
});
}
private void setupMap() {
mMap.setMyLocationEnabled(true);
// ...
}
}
Try to add the Marker & PolyLines in the map using below code:
GoogleMap mMap;
static final CameraPosition BONDI =
new CameraPosition.Builder().target(new LatLng(-33.891614, 151.276417))
.zoom(15.5f)
.bearing(300)
.tilt(50)
.build();
changeCamera(CameraUpdateFactory.newCameraPosition(BONDI));
mMap.addMarker(new MarkerOptions().position(new LatLng(-33.891614, 151.276417)).title("Bondi"));
private void changeCamera(CameraUpdate update) {
changeCamera(update, null);
}
/**
* Change the camera position by moving or animating the camera depending on the state of the
* animate toggle button.
*/
private void changeCamera(CameraUpdate update, CancelableCallback callback) {
boolean animated = ((CompoundButton) findViewById(R.id.animate)).isChecked();
if (animated) {
mMap.animateCamera(update, callback);
} else {
mMap.moveCamera(update);
}
}
Add the PolyLines as below:
// A simple polyline with the default options from Melbourne-Adelaide-Perth.
mMap.addPolyline((new PolylineOptions())
.add(BONDI));