I'm looking to do something like what is done right here in Android. What I need to do is group markers into different groups and have checkboxes to each group.
When I tick and untick on the check boxes markers should be show and hide.
Here is my MapsActivity.java file.
public class MapsActivity extends FragmentActivity {
private final LatLng LOCATION_RESTAUTRNT = new LatLng(6.9270786,79.861243);
private final LatLng LOCATION_PARK = new LatLng(6.0334009,80.218384);
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
Button buttonloc1 = (Button)findViewById(R.id.btnLoc1);
buttonloc1.setText("Restaurant");
Button buttonloc2 = (Button)findViewById(R.id.btnLoc2);
buttonloc2.setText("Park");
Button buttoncity = (Button)findViewById(R.id.btnCity);
buttoncity.setText("My Location");
Button buttonremove = (Button)findViewById(R.id.removeMarker);
buttonremove.setText("Remove");
ArrayList<Marker> myMarkers = new ArrayList<Marker>();
mMap.addMarker(new MarkerOptions()
.position(LOCATION_RESTAURANT)
.title("Hi I'm in Restaurant..:D")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))
);
mMap.addMarker(new MarkerOptions()
.position(LOCATION_PARK)
.title("Hi I'm in Park..:D")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE))
);
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
}
});
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
public void onClick_City(View v){
mMap.setMyLocationEnabled(true);
}
public void onClick_Loc1(View v) {
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_RESTAURANT,10);
mMap.animateCamera(update);
}
public void onClick_Loc2(View v) {
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_PARK,10);
mMap.animateCamera(update);
}
public void onClick_Remove(View v){
mMap.clear();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
I just put two markers in here and I need someone's help to do what I want.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire