I'm new in this programming language so I kinda copy and paste the codes found in the net and then I've found and tried using these codes in bounding a certain area and it works:
private GoogleMap mMap;
// Create a LatLngBounds that includes the city of Adelaide in Australia.
private LatLngBounds ADELAIDE = new LatLngBounds(
new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
// Constrain the camera target to the Adelaide bounds.
mMap.setLatLngBoundsForCameraTarget(ADELAIDE);
But when I changed it using my campus coordinates into like this:
private LatLngBounds CPUBounds = new LatLngBounds(
new LatLng(10.732581, 122.548413), new LatLng(10.730052, 122.549958));
My app suddenly stop working. What should I do?
Try to paste the Logcat to review the Error
From If you want to show the specific position try the following code
To Move Camera Position Over a Specific Region Use this ,
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,
zoomWidth,
zoomHeight,
zoomPadding));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(10.732581, 122.548413),
zoomHeight));
If u want to add a marker Over region use
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10.732581, 122.548413))
.title("campus name"));
To Disable the Dragging Use
mMap.getUiSettings().setScrollGesturesEnabled(false);
but it doesn't disable map zoom by touch on map. for that use Following Code
googleMap.getUiSettings().setZoomGesturesEnabled(false);
Related
I have a GoogleMap (Lite Mode) object that has been properly initialized. It works properly with a single Marker and focuses on the proper area using CameraUpdate with newLatLngZoom.
However, when it comes to adding two markers, and have the map keep both in view using LatLngBounds, everything goes bonkers. The map is so zoomed out it shows the entire continent, and the two markers are on-top of each other (along with the polyline).
Kindly assume that the data from the pickup and destination is correct
Here's my code:
googleMap.addMarker(new MarkerOptions()
.position(pickup)
.title(job.getPickupAddress()));
googleMap.addMarker(new MarkerOptions()
.position(destination)
.title(job.getDestinationAddress())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(new LatLngBounds.Builder().include(pickup).include(destination).build(), 0);
googleMap.moveCamera(cameraUpdate);
String pickupLatLng = job.getPickupLatLong().latitude + "," + job.getPickupLatLong().longitude;
String destinationLatLng = job.getDestinationLatLong().latitude + "," + job.getDestinationLatLong().longitude;
plotPolyLines(pickupLatLng, destinationLatLng);
Output:
Setting a zoom with latlng bounds is not an effective solution for all use cases.
Might be a related Bug Maps Lite mode with incorrect zoom level first time app starts
Try few solutions / hacks listed here : https://issuetracker.google.com/issues/36218443
Like refreshing the map by destroying and recreating
Also check if by using a single marker with bounds builder if the map sets to the proper zoom level
One last thing make sure that zoom level limits have not been applied.
try changing the line
googleMap.moveCamera(cameraUpdate);
to
googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
as suggested in How do I set default location and Zoom level for google map api v2?
or use
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
That should move the camera closer to your marker.
I want a Map UI like above dotted circle route path .I searched a lot through web and stack overflow i cant find any source.
I tried
addCircle polyline but the circle is large when i zoom the camera to
an extend in google map
I don't know how google map implemented it either with marker or
polyline
Provided help is appreciated rather than downvotes!!
thanks :-)
You can use Stroke Patterns for polylines like this:
#Override
public void onMapReady(GoogleMap googleMap) {
List<LatLng> sourcePoints = new ArrayList<>();
sourcePoints.add(new LatLng(22.724526, 75.825979));
sourcePoints.add(new LatLng(22.720165, 75.905953));
sourcePoints.add(new LatLng(22.766649, 76.075773));
sourcePoints.add(new LatLng(22.862032, 76.098302));
PolylineOptions polyLineOptions = new PolylineOptions();
polyLineOptions.addAll(sourcePoints);
polyLineOptions.width(50f);
polyLineOptions.color(Color.rgb(0, 178, 255));
Polyline polyline = googleMap.addPolyline(polyLineOptions);
List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dot(), new Gap(10f));
polyline.setPattern(pattern);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(sourcePoints.get(2))
.zoom(14)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
to get result like that:
Unfortunately it's impossible to draw bigger circles under smaller to achieve "bordered" circles path because of nonlinear dependency between Dot() and Gap() sizes.
Or you can draw whatever you want on MapVew canvas via overriding dispatchDraw() of MapView like in this answer (it's about MapBox MapView, but approach is applicable for Google Maps MapView too).
I think its overkill, but you can use some of Google APIs from https://console.developers.google.com/apis/library
and get path and make from them set of LatLngs, then draw them on googleMap just like normal marker, but with small round circle as icon.
To be honest, I am not sure what you want to achieve, I think simpler idea is to use origin and destination and open it in GoogleMaps Android App - do not reinvent the wheel.
I'm new to android development.
I need to load a custom google-map someone made in google maps (a map with marks and information).
My question is how to load this map on a android app (and not just creating a new map and manually adding all the markers and information -- because than each time client wants to change something in the map he will need to change it in 2 places).
I know i can just make a webview but than i can't access the location and focus on users location -- is there any other way?
Thanks for the help!
You can take the location of your indicated region and add the markers manually if there isn't place to mark.
static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
https://developers.google.com/maps/documentation/android-api/marker
i am working on a project, where i have to add a marker using overlay to existing Google map.
i have multiple markers along with infoWindowAdapter,for these i must pass title and snippet. I need one more marker to show only title(i can't directly add a marker with only title,since i used infoWindow for markers it will asks for snippet and ended up with null pointer exception)
I tried this
LatLng currenLoc = new LatLng(location.getLatitude(), location.getLongitude());
Toast.makeText(getApplicationContext(), ""+currenLoc, Toast.LENGTH_SHORT).show();
GroundOverlayOptions curLoc = new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.mrk1)).position(currenLoc, 350f, 350f);
gMap.addGroundOverlay(curLoc);
but it shows only a marker like picture not an exact marker. So how to add a marker using ground overlay.?
Hi I have created a map as well as some markers which indicate places/locations on the map. Is there any possible way of creating an animation between those location? For instance drawing a polyline between 2 different locations and create an animation from a start point to an end point ? Is there any documentation for such a thing or any tutorials ? Many thanks.
Something like this:
https://www.youtube.com/watch?v=HPWYorS68WE
use this code and you can also follow this link
https://developers.google.com/maps/documentation/android/
Flat Markers
LatLng mapCenter = new LatLng(41.889, -87.622);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
// Flat markers will rotate when the map is rotated,
// and change perspective when the map is tilted.
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.direction_arrow))
.position(mapCenter)
.flat(true)
.rotation(245));
CameraPosition cameraPosition = CameraPosition.builder()
.target(mapCenter)
.zoom(13)
.bearing(90)
.build();
// Animate the change in camera view over 2 seconds
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
2000, null);
}