Is there any way to prevent user scroll pass a specific area using Google map?
I added a ground overlay on the map, and I don't want user scroll pass it. I found https://developers.google.com/maps/documentation/android-api/views#restrict-panning but user still can see a little map around the overlay (see image below). Any suggestions will be appreciated.
My code:
#Override
public void onMapReady(final GoogleMap mMap) {
final LatLngBounds bounds = new LatLngBounds(new LatLng(10.762657076386494, 106.65704530350968), new LatLng(10.783062032257044, 106.67223733537003));
mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.images))
.positionFromBounds(bounds));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 18));
mMap.setLatLngBoundsForCameraTarget(bounds);
}
Related
Android Google maps V2 How to draw a Custom Views(1/3 filled circle) on map where can i get canvas object to draw.As all new classes are final classes I can't extend them.
I need to draw a some cutom views on the map.I am upgrading from v1 to v2.The Overlays has been deprecated.I tries with Tile Provider but it is not drawing anything.
exampleButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
GroundOverlayOptions overlayOptions = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.testImage))
.position(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 8600f, 6500f);
map.addGroundOverlay(overlayOptions);
}
});
This is the code to draw an image at a specified lat long which is working for google maps v2. You can basically get an image of 1/3 filled circle and set it to the lat long you want.
Hope it helps.
I am using the google maps api v2 for my new google maps app. And I wondered how to calculate the coordinates of 4 edges of the current screen position so that I can search for markers that are directly in the camera view. Any ideas about how it is possible to achieve ? I thought about something with the center of the camera view and zoom but can't figure out how to continue.
Here is the proper answer to get the coordinates of upper right corner and down left corner:
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
//fetchData(bounds);
ne = bounds.northeast;
sw = bounds.southwest;
//new DownloadJSON().execute();
//Log.e("LatLngs"," southwest: "+sw+" northeast: "+ne);
}
});
In my project i want to add image at particular location in map.For that i used the following code.
public class Sample extends Activity {
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
LatLng sydney = new LatLng(33.6671688,-117.9053506);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 15));
//add overlay
BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.categorymap);
GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
.image(image)
.position(sydney, 1000f)
.transparency(0.1f);
map.addGroundOverlay(groundOverlay);
}
}
By using this code the map is displayed like the following screenshot.
But my requirement is add the image at particular location like the following screenshot.For that i have latitude and longitude values also to show the map location.In that location i want to add the image like following screenshot.
So my question is,how to move the image from left to right like the above screenshot.I tried alot for doing this but didnt solve the issue.So please suggest me how to solve this problem.Thanks inadvance to all...
Try to get the exact positions of the corners of the building and uses the method
public GroundOverlayOptions positionFromBounds (LatLngBounds bounds)
Then it should scale with the mapzoom
Another way is to use anchor
EDIT:
GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
.image(image)
.position(sydney, 1000f)
.transparency(0.1f)
.anchor(0.5, 0.5);
This will instead make the lat/lon to be in center of your image.
I have a google map (com.google.android.gms.maps.GoogleMap) where I have some markers set.
I am able to, separately,
1) adjust zoom level and center the map on a boundary:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
and
2) center the map above one of the markers:
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
but, for the life of me, I can't just do both, adjust the zoom level using newLatLngBounds and then center the map somewhere else. Whatever I do last is what I see happening in the map.
How do I do this?
For future visitors this is how you can chain camera animations:
map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {
#Override
public void onFinish() {
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
}
#Override
public void onCancel() {
}
});
Also see AnimateCameraChainingExampleActivity.java for an example how to chain infinitely.
Try using both moveCamera and animateCamera...
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
moveCamera will move directly to that spot while animateCamera will provide the moving effect. They are linear in nature so one will happen after the other however layering them as I have done above will provide the potential effect you are looking for.
If you are trying to see the actual movement of both calls on the UI you will need to register for the callback post the completion of the animation as needed.
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));
}