I'm creating my own icon marker in ClusterManager in GoogleMap.
I hide the Google Marker with:
item.getMarker().setAlpha(Constants.MARKER_ALPHA_IS_INVISIBLE);
and in MarkerOptions, I set the alpha to 1.
Unfortunately, when I try to hide a marker in map or delete it from the Cluster, the position of cluster in map breaks. For example, I have a marker in Berlin and the markers are well clustered, but when I zoom GoogleMap, this cluster goes to Russia.
#Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.title(String.valueOf(item.getMarker().getTitle()));
Bitmap markerBitmap = item.getBitmap();
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(markerBitmap);
markerOptions.icon(bitmapDescriptor);
markerOptions.getIcon().zzvg();
markerOptions.alpha(Constants.MARKER_ALPHA_IS_VISIBLE);
item.getMarker().setAlpha(Constants.MARKER_ALPHA_IS_INVISIBLE);
}
Related
Is there any way by which we can show the particular country as default country in google map?
I have tried with the centre of some of the countries but it seems tedious.
I have only country name say "India" and I need to do is, show "India" in focus when the app gets open.
In your onMapReady() function set
LatLngBounds boundsIndia = new LatLngBounds(new LatLng(23.63936, 68.14712), new LatLng(28.20453, 97.34466));
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(boundsIndia, padding);
mMap.animateCamera(cameraUpdate);
When you open your map you will see only India country on map.
You can do it for any other countries.
This shows Sydney and puts a marker on it https://developers.google.com/maps/documentation/android-api/map-with-marker
public class MapsMarkerActivity extends AppCompatActivity
implements OnMapReadyCallback {
// Include the OnCreate() method here too, as described above.
#Override
public void onMapReady(GoogleMap googleMap) {
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
I have made a custom marker,it comes perfectly when map is loaded,but my problem is when i zoom in or out the map,marker changes its position and also when i click on marker info window comes on another postition(not on its top),My code is as below,I cant find solution or idea what i have made wrong,Please save me.
code
private void plotMarkers(ArrayList<MyMarker> markers) {
if (markers.size() > 0) {
for (MyMarker myMarker : markers) {
System.out.println("================rounded bitmaps==========="
+ roundedBitmaps.toString());
// Create user marker with custom icon and other options
MarkerOptions markerOption = new MarkerOptions()
.position(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude()));
markerOption.icon(BitmapDescriptorFactory.fromBitmap(myMarker
.getImgURL()));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(myMarker.getmLatitude(), myMarker
.getmLongitude())).zoom(12).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
Marker currentMarker = mMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
Custom Markers work in a different way as the standard markers. The problem you are facing is a known issue, The best way to deal with this are as follows:
Make sure that the image for the custom marker is symmetrical and id perfectly aligned to the anchor.
The info window should also be similarly aligned symmetrically in the center of the marker, else it will look ugly. Please note that the Custom marker icons often require a different anchor. For the info window, use a custom info window layout (with a custom background) to align it correctly to the marker.
i am using google map V2 in android, user can only view the map all other zooming spaning is set to diabled. Position of marker update after some intervals, now i want when ever the position of marker goes out of view bound the marker get centred as well as the map. so the user just see the current marker postion.
Use This:
LatLngBounds.Builder bld = new LatLngBounds.Builder();
bld.include(new LatLng(your latitude, your longitude));
LatLngBounds latLngBounds = bld.build();
yourMap.moveCamera(CameraUpdateFactory.newLatLngBounds(
latLngBounds, 50));
I am able to display a marker as well as showing it with zoom and camera setting when first time user is viewing the map. But my requirement is to move the camera to same marker position(when user want) if user goes away from that marker position(marker gets off-screen) during his/her visit.
Having a reference to the GoogleMap object and to the Marker, you can simply use
GoogleMap mMap;
Marker mMarker;
[...]
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mMarker.getPosition(), 14));
(where you would substitute the "14" for your desired level of zoom).
Just attach that line to the OnClick event of the button that the user will click to "get back" to the marker... and you're done! ;)
Thanks for replies,
but i was looking for some native Map component to perform the map marker reset task rather than an external button to navigate back to desired marker location. I got this working with the latest update in Map Api(to have setOnMyLocationButtonClickListener) Using below code:-
mMap.setMyLocationEnabled(true);
LatLng markerLoc=new LatLng(companyDetail.getLatitude(), companyDetail.getLongitude());
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(markerLoc) // Sets the center of the map to Mountain View
.zoom(13) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); //
mMap.addMarker(new MarkerOptions().position(new LatLng(companyDetail.getLatitude(), companyDetail.getLongitude())).title("Marker"));
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mMap.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
#Override
public boolean onMyLocationButtonClick() {
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
return true;
}
});
you can use [animateCamera][1] function of GoogleMap object
GoogleMap googleMap = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map).getMap();
googleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
[1]: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap#animateCamera%28com.google.android.gms.maps.CameraUpdate%29
You can also use like this :
LatLng cur_Latlng=new LatLng(21.0000,78.0000); // giving your marker to zoom to your location area.
gm.moveCamera(CameraUpdateFactory.newLatLng(cur_Latlng));
gm.animateCamera(CameraUpdateFactory.zoomTo(4));
// another method is to use current location
#Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 4);
gm.animateCamera(cameraUpdate);
Marker myMarkerthirtyfour = gm.addMarker(new MarkerOptions()
.position(latLng)
.title("You are here")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
locationManager.removeUpdates(this);
}
I am using Google maps api v2 in android. I have placed a marker by using latitude and longitude . The marker is shown at correct place , but i want the the map should show area around the marker only .i.e i want to zoom to markers position when the map is shown so it shows nearby region of the marker only..any help would be great.
pass your current location in this function where you have placed your marker.
private void moveToCurrentLocation(LatLng currentLocation)
{
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,15));
// Zoom in, animating the camera.
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
Provide marker position.
private void pointToPosition(LatLng position) {
//Build camera position
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(position)
.zoom(17).build();
//Zoom in and animate the camera.
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}