Skip to content

Instantly share code, notes, and snippets.

@amalChandran
Created January 13, 2017 04:51
Show Gist options
  • Save amalChandran/60298401142a97191d7b706f1db55ab0 to your computer and use it in GitHub Desktop.
Save amalChandran/60298401142a97191d7b706f1db55ab0 to your computer and use it in GitHub Desktop.
How to Set Polyline fit to screen
public void onMapReady(GoogleMap googleMap) {
map.clear();
map = googleMap;
LatLng hcmus = new LatLng(Double.parseDouble(latitude1), Double.parseDouble(longitude1));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(hcmus, 10));
originMarkers.add(map.addMarker(new MarkerOptions()
.title(mStudentObject.getAddress())
.position(hcmus)));
LatLng startMarker=new LatLng(Double.parseDouble(latitude1),Double.parseDouble(longitude1));
LatLng endMarker=new LatLng(latitudeuser,longitudeuser);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(startMarker);
builder.include(endMarker);
LatLngBounds bounds = builder.build();
int padding = 0; // padding around start and end marker
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.animateCamera(cu);
googleMap.setTrafficEnabled(false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
googleMap.setMyLocationEnabled(true);
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
Log.e("bhb",marker.getTitle());
return null;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment