I am using this code for load google map
private GoogleMap myMap;
if(myMap!=null){
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
marker = myMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getAddress(latitude, longitude)));
Location = new LatLng(latitude, longitude);
CameraPosition cameraPosition = new CameraPosition.Builder().target(Location).zoom(15)
.bearing(90) // Sets the orientation of the camera to
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
// myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15));
}
but map is not loading and occurring this issue
You must install the latest Google play services in your phone/tab/emulator before running the app.
For google play on emulator.
Related
I'm using the Google Maps API and I want to set my camera on a specific marker. When I do this and I start rotating my camera is losing focus on my marker while they both have the same coordinate.
Does someone knows why this is happening?
My code
LatLng myCoordinates = new LatLng(location.getLatitude(), location.getLongitude());
player.setPosition(myCoordinates);
CameraPosition currentPosition = map.getCameraPosition();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(myCoordinates)
.bearing(currentPosition.bearing)
.zoom(18)
.tilt(currentPosition.tilt)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Click here for a video of the problem. (The orange marker is one that the camera is set on)
how can i set the zoom level of a SupportMapFragment ?
I tried some answers I found in similar questions, like this one answered buy a guy named Rob who proposed:
LatLng currentLocation = mService.getCurrentLocation();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(currentLocation) // Sets the center of the map to the current location of the user
.zoom(17) // 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(); // Creates a CameraPosition from the builder
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
But this solution didn't work. So, how can I set the Zoom level knowing that I use a SupportMapFragment.
if your current location is not null then try this code it will work
LatLng currentLocation = mService.getCurrentLocation();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(currentLocation , 16);
mMap.addMarker(new MarkerOptions().position(location).title(""));
mMap.moveCamera(CameraUpdateFactory.newLatLng(currentLocation ));
mMap.animateCamera(cameraUpdate)
Marker currentMarker;
MarkerOptions marker = new MarkerOptions().position(new
LatLng(Double.
parseDouble(lat),Double.parseDouble(lon))).title(title);
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus));
currentMarker = map.addMarker(marker);
currentMarker.showInfoWindow();
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(lat),Double.parseDouble(lon)), 15));
I want to set a google map location with lat/long so that it can't be changed by user. How to do it?
double latitude = 35.6961;
double longitude = 51.4231;
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Hello Maps");
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
googleMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(35.6961, 51.4231)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
Try to add this line below your code.
googleMap.getUiSettings().setScrollGesturesEnabled(false);
This will forbid the user to scroll the map.
Hi I am trying to change the camera in different locations with an animation. What happens is that when the map opens it zooms to a location then it stops for 6 secs and then it moves to another location with a camera animation. My question is that when this is finished how can I create a 3rd location and then move the camera from the 2nd location to the 3rd? Any idea guys ? Thanks. Here is my code.
public class THEMAP extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng loc1 = new LatLng(41.889, -87.622);
LatLng loc2 = new LatLng(45.889, -87.622);
LatLng loc3 = new LatLng(49.889, -87.622);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc1, 10));
map.animateCamera(CameraUpdateFactory.zoomIn());
map.animateCamera(CameraUpdateFactory.zoomTo(10), 6000, null);
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc2)
.flat(true)
.rotation(245));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc1)
.flat(true)
.rotation(245));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc3)
.flat(true)
.rotation(245));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(mapCenter2)
.zoom(8)
.bearing(90)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition ),
8000, null);
}
}
The problem is that if i add another location+marker and try to do the above code, the map animates only the 3rd location ignoring the animation of the 2nd location. Any advice guys ?Please help.
CameraPosition cameraPosition2 = new CameraPosition.Builder()
.target(loc3)
.zoom(8)
.bearing(90)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition2 ),
8000, null);
Here's your answer: http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part3
It seems you need to implement the second animation in the onFinish() callback of the second animation.
I have got the following code, and what I want to do is to open "Google Maps" APP [How to go] to the marker I have set up:
// S E T M A P P O I N T
mLocationClient = new LocationClient(this, this, this);
mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.setOnMapClickListener(this);
map.setMyLocationEnabled(true);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), ZOOM));
map.clear();
addressText = GetGeolocation.getgeocoder(Date_Accept.this, latitude, longitude);
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(addressText)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
marker.showInfoWindow();
How can I open "Google Maps" app to get the route to that point?
you should be able to fire an intent with the maps url and let android handle it for you
read about that here