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));
}
Related
I have a slinding up panel in an activity and i need the panel to be expanded on start, so when I do it it covers up the marker. How do I make the focus of the map be a little higher.
I tried the tilt provided in google map android documentation but it didn't work as I expected.
#Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
LatLng temp = new LatLng(46.8182, 8.2275);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(temp, 8.0f));
}
I need the map to be a little higher. So the marker shouldn't be centered as many questions here ask. I need it to be NOT centered.
Use this
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(temp) // 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();
The answer to this is using setPadding in google maps.
googleMap.setPadding(leftPx, topPx, rightPx, bottomPx);
I am using Mapbox android sdk for my map application, i want to use pointer icon('myIcon' in this case) which always points in the direction where user is moving.
I here is my code :
public void addMarker(MapboxMap mapboxmap) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}
With marker views we don't expose a way to do this, and your only option is to adjust the marker rotation when the camera is rotated. A better solution would be to use runtime styling and a symbol layer. An example of this can be found in our demo app. To ensure that the marker always points in the correct direction you can use the icon-rotation-alignment property and set it to map. Hope this helps!
Setting rotation on location update {like setRotation(angle_you_want_to_set)} worked of me.
Example :
public void addMarker(MapboxMap mapboxmap, float angle) {
// marker view options : setting location and icon
MarkerViewOptions options = new MarkerViewOptions()
.position(latLng)
.anchor(0.5f, 0.5f)
//set angle of ration for icon
.setRotation(angle)
.icon(myIcon);
MarkerView view = options.getMarker();
// added marker on map
mapboxMap.addMarker(options);
}
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);
}
});
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);
}