Android: GoogleMaps on fragment LongPressClick doesn't work - android

I want to pin a new mark on my map but method onMapLongClick didn work.
My code is below. I have my map inside a fragment.
public class Fragment_maps extends android.support.v4.app.Fragment
implements OnMapLongClickListener, OnMapClickListener{
MapView mMapView;
private GoogleMap googleMap;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflate and return the layout
View v = inflater.inflate(R.layout.fragment_maps, container,
false);
mMapView = (MapView) v.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
//activate menu button
setHasOptionsMenu(true);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
//get the map
googleMap = mMapView.getMap();
// Detect location
googleMap.setMyLocationEnabled(true);
//googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// Turns traffic layer on
googleMap.setTrafficEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Turns on 3D buildings
googleMap.setBuildingsEnabled(true);
// Show Zoom buttons
googleMap.getUiSettings().setZoomControlsEnabled(true);
// latitude and longitude
double latitude = 40.639350;
double longitude = 22.944607;
// create marker
MarkerOptions thessaloniki = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Thessaloniki");
//----------------
MarkerOptions LeykosPyrgos = new MarkerOptions().position(new LatLng(40.626401, 22.948352)).title("Leykos Pyrgos");
// Changing marker icon
thessaloniki.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
//----------------
LeykosPyrgos.icon(BitmapDescriptorFactory .fromResource(R.drawable.whitetower));
// adding marker
googleMap.addMarker(thessaloniki);
CameraPosition cameraPositionThess = new CameraPosition.Builder() .target(new LatLng(40.639350, 22.944607)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPositionThess));
//----------------
googleMap.addMarker(LeykosPyrgos);
CameraPosition cameraPositionLeykosPyrgos = new CameraPosition.Builder() .target(new LatLng(40.626401, 22.948352)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPositionLeykosPyrgos));
// Perform any camera updates here
return v;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_maps, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d("onOptionsItemSelected","yes");
switch (item.getItemId()) {
case R.id.HYBRID:
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);;
return true;
case R.id.SATELLITE:
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
return true;
case R.id.TERRAIN:
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
return true;
case R.id.NORMAL:
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onMapClick(LatLng point) {
Toast.makeText(getActivity(),point.toString(),Toast.LENGTH_SHORT).show();
googleMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
#Override
public void onMapLongClick(LatLng point) {
googleMap.addMarker(new MarkerOptions()
.position(point)
.title("You are here")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
}
#Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
}
As you can see I have both onMapClick and onMapLongClick methods but when I click on map nothing happens. I also have implement OnMapLongClickListener and OnMapClickListener. What am I doing wrong?
Thanks in advance.

Your class implements the listener but you don't set it:
googleMap.setOnMapLongClickListener(this);
same with the normal click listener:
googleMap.setOnMapClickListener(this);

Related

Android: error with map fragment on navigation drawer and permission check

I started working on an old application i have that uses a map fragment on a navigation drawer. It used to work OK but now, with the new permisson thing, I get some errors. I have searched on SO and on the internet generally but I dont know what I am missing. My map Fragment is below
public class Fragment_maps extends android.support.v4.app.Fragment implements OnMapLongClickListener, OnMapClickListener, OnMapReadyCallback {
MapView mMapView;
GoogleMap googleMap;
#Override
public void onMapReady(GoogleMap googleMap) {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// inflate and return the layout
View v = inflater.inflate(R.layout.fragment_maps, container, false);
mMapView = (MapView) v.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
//activate menu button
setHasOptionsMenu(true);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
//get the map
mMapView.getMapAsync(this);
// Detect location
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
//googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// Turns traffic layer on
googleMap.setTrafficEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Turns on 3D buildings
googleMap.setBuildingsEnabled(true);
// Show Zoom buttons
googleMap.getUiSettings().setZoomControlsEnabled(true);
// latitude and longitude
double latitude = 40.639350;
double longitude = 22.944607;
googleMap.setOnMapLongClickListener(this);
googleMap.setOnMapClickListener(this);
// create marker
MarkerOptions thessaloniki = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Thessaloniki");
// Changing marker icon
thessaloniki.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
// adding marker
googleMap.addMarker(thessaloniki);
CameraPosition cameraPositionThess = new CameraPosition.Builder() .target(new LatLng(40.639350, 22.944607)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPositionThess));
// Perform any camera updates here
return v;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_maps, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d("onOptionsItemSelected","yes");
switch (item.getItemId()) {
case R.id.HYBRID:
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
return true;
case R.id.SATELLITE:
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
return true;
case R.id.TERRAIN:
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
return true;
case R.id.NORMAL:
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onMapClick(LatLng point) {
Toast.makeText(getActivity(),point.toString(),Toast.LENGTH_SHORT).show();
googleMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
#Override
public void onMapLongClick(LatLng point) {
if (SelectUserActivity.flagOwner){
googleMap.addMarker(new MarkerOptions()
.position(point)
.title(MainActivity.onomaxarth)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
Toast.makeText(getActivity(),"Hotel pinned at: "+point.toString(),Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getActivity(),point.toString(),Toast.LENGTH_SHORT).show();
}
}
#Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
I used googleMap = mMapView.getMap(); to get the map but i have change it with mMapView.getMapAsync(this); by implementing OnMapReadyCallback and it forced me to create the onMapReady method, which I dont know how it is different from the onCreateView method so i leave it empty.
Now i get an error on googleMap.setMyLocationEnabled(true); for permission and when i debug my app the googleMap object is null.
When I run it, on selecting the map fragment the app crashes and terminates the activity that holds the Fragments.
On the Manifest i have
android:minSdkVersion="17"
android:targetSdkVersion="23"
and my gradle dependencies are
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:+'
What am i missing here? How can i use the permission in the fragment and why googleMap is empty?
Move this code from your onCreateView to your onMapReady:
// Detect location
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
//googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// Turns traffic layer on
googleMap.setTrafficEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Enables indoor maps
googleMap.setIndoorEnabled(true);
// Turns on 3D buildings
googleMap.setBuildingsEnabled(true);
// Show Zoom buttons
googleMap.getUiSettings().setZoomControlsEnabled(true);
// latitude and longitude
double latitude = 40.639350;
double longitude = 22.944607;
googleMap.setOnMapLongClickListener(this);
googleMap.setOnMapClickListener(this);
// create marker
MarkerOptions thessaloniki = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Thessaloniki");
// Changing marker icon
thessaloniki.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
// adding marker
googleMap.addMarker(thessaloniki);
CameraPosition cameraPositionThess = new CameraPosition.Builder() .target(new LatLng(40.639350, 22.944607)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPositionThess));
The line mMapView.getMapAsync(this); prepares the map and onMapReady gets called when the map is ready to be used.
Also, if you have defined private GoogleMap googleMap;, you will want to add this to the beginning of your onMapReady method:
this.googleMap = googleMap;

Map does not detect touches/swipes in android

I followed this tutorial to add a map to one of my tabs. It works, but when I open the map tab I cannot swipe up/down, zoom in/out (except when I double click). Swiping left/right works, but the map moves very little. I made a customViewPager, and it disables swiping the tabs, but does nothing for he map.
At first I used tabActivity and my map fragment worked as it should, and looked like this:
mapActivity extends FragmentActivity...
Since tabActivity is deprecated I added sliding tabs, following the tutorial above. Map could not be added with FragmentActivity, only with Fragment so I changed map fragment to:
mapActivity extends Fragment...
Now I have the following problem - I cannot navigate the map. Swipe and touch inputs are not detected. I cannot move up or down, zoom in or out, and the only thing I can do is move from left to right, but it is very slow.
Try this. its sample . 100% working
public class Map extends Fragment {
final int RQS_GooglePlayServices = 1;
Location myLocation;
TextView tvLocInfo;
boolean markerClicked;
PolygonOptions polygonOptions;
Polygon polygon;
// GPSTracker class
GPSTracker gps;
double latitude;
double longitude;
MapView mapView;
GoogleMap map;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_map_fragment, container, false);
// TODO Auto-generated method stub
MapsInitializer.initialize(getActivity());
switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity())) {
case ConnectionResult.SUCCESS:
Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show();
mapView = (MapView) rootView.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
if (mapView != null) {
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 13);
map.animateCamera(cameraUpdate);
}
break;
case ConnectionResult.SERVICE_MISSING:
Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show();
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show();
}
gps = new GPSTracker(getActivity());
if (gps.canGetLocation()) {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
// \n is for new line
// Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
} else {
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}
// tvLocInfo = (TextView) findViewById(R.id.locinfo);
/* FragmentManager myFragmentManager = getFragmentManager();
MapFragment myMapFragment
= (MapFragment) myFragmentManager.findFragmentById(R.id.map);
map = myMapFragment.getMap();*/
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
markerClicked = false;
map.setMyLocationEnabled(true);
map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(11);
map.moveCamera(center);
map.animateCamera(zoom);
}
});
/* LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
if (location != null)
{
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(40) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}*/
// Updates the location and zoom of the MapView
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
/* TextView tv = (TextView) getActivity().findViewById(R.id.textset);
tv.setText("Audio");*/
}
#Override
public void onResume() {
mapView.onResume();
super.onResume();
}
#Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
At first I added tabLayout and viewPager to appBarLayout in app_bar_main (I made an app with navigation drawer), and later I moved the appBarLayout to content_main and it worked.

reposition a marker when I press button android API V2

I have the following code and, when I press a menu button I would like to reposition the same marker and the camera but I do not have idea how to do it, I've read oficial documentation but I haven't found info. I'm using repositionMarker() method to do it, but Im not sure what to do. Thanks
public class Init extends AppCompatActivity implements OnMapReadyCallback
{
private MapFragment map;
static final LatLng PERTH = new LatLng(19.0436, -98.1981);
private CameraUpdate camaraloc, camaraloczoom;
private Marker markerloc;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio);
map = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
if (map != null)
{
map.getMapAsync(this);
}
}
#Override
public void onMapReady(GoogleMap map)
{
map.setMyLocationEnabled(true);
camaraloc = CameraUpdateFactory.newLatLng(PERTH);
camaraloczoom = CameraUpdateFactory.zoomTo(8);
map.moveCamera(camaraloc);
map.animateCamera(camaraloczoom);
markerloc = map.addMarker(new MarkerOptions().position(PERTH)
.title("city").snippet("esp").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_inicio, menu);
return true;
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
drawerLayout.openDrawer(GravityCompat.START);
return true;
case R.id.action_settings:
Toast.makeText(this, "name marker: "+markerloc.getTitle(), Toast.LENGTH_SHORT).show();
reposicionMarker();
return true;
}
return super.onOptionsItemSelected(item);
}
public void repositionMarker()
{
camaraloc = CameraUpdateFactory.newLatLng(new LatLng(16.65, -91.8658));
camaraloczoom = CameraUpdateFactory.zoomTo(15);
if ( markerloc != null )
markerloc.remove();
markerloc.setPosition(new LatLng(16.65, -91.8658));
// here is where I dont know what to do
}
}
Calling setLocation on the Marker should work, for changing its location. What seems to be your problem is that you are actually removing the marker right before you set the new location.

How to get lat n lng center point of map in android?

I am building an android application where user is getting latLng by long touching in Google map.
Here is the code:
public class MainActivitytut extends FragmentActivity{
GoogleMap googleMap;
MarkerOptions markerOptions;
LatLng latLng;
private TextView myAddress;
String lat;
TextView txtmapinfo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maintut);
//onBackPressed();
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
// Getting a reference to the map
googleMap = supportMapFragment.getMap();
// Setting a click event handler for the map
googleMap.setOnMapClickListener(new OnMapClickListener() {
#Override
public void onMapClick(LatLng arg0) {
// Getting the Latitude and Longitude of the touched location
latLng = arg0;
lat = latLng.toString();
// Toast.makeText(getApplicationContext(), lat,
// Toast.LENGTH_LONG).show();
// getMyLocationAddress();
// Clears the previously touched position
googleMap.clear();
// Animating to the touched position
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
// Creating a marker
markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(latLng);
// Placing a marker on the touched position
googleMap.addMarker(markerOptions);
// Adding Marker on the touched location with address
new ReverseGeocodingTask(getBaseContext()).execute(latLng);
}
});
}
protected void putExtra(String string, CharSequence text) {
// TODO Auto-generated method stub
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
// present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I had used lat = map.getCameraPosition().target; and when I toast the value of lat, it is toasting 0.0
What I need is that when on swiping the map the latlng change and toast.
Wait until the map has loaded and then call getCameraPosition:
mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
#Override
public void onMapLoaded() {
LatLng pos = mMap.getCameraPosition().target;
Log.e("", "Pos: " + pos.toString());
mMap.addMarker(new MarkerOptions().position(pos));
}
});

how to show map of specific city in google map when app start

below is my code which display map of all world i want when application start is show specific city not world map i follow this tutorial http://android-er.blogspot.com/2013/01/google-maps-android-api-v2-example-draw.html every thing work fine but i want when app start first time is display specific city map not all global map i dont want show globap map like this image http://1.bp.blogspot.com/-dwjqTWCdONg/UObUk1syAFI/AAAAAAAAGy8/S43YMKuXZRc/s1600/screen_MapsAPIv2_Polygon.png on app start i want specific city map like newyork for example.
public class MainActivity extends Activity
implements OnMapClickListener, OnMapLongClickListener, OnMarkerClickListener{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
Location myLocation;
TextView tvLocInfo;
boolean markerClicked;
PolygonOptions polygonOptions;
Polygon polygon;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvLocInfo = (TextView)findViewById(R.id.locinfo);
FragmentManager myFragmentManager = getFragmentManager();
MapFragment myMapFragment
= (MapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
myMap.setOnMarkerClickListener(this);
markerClicked = false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected void onResume() {
super.onResume();
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"isGooglePlayServicesAvailable SUCCESS",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
RQS_GooglePlayServices);
}
}
#Override
public void onMapClick(LatLng point) {
tvLocInfo.setText(point.toString());
myMap.animateCamera(CameraUpdateFactory.newLatLng(point));
markerClicked = false;
}
#Override
public void onMapLongClick(LatLng point) {
tvLocInfo.setText("New marker added#" + point.toString());
myMap.addMarker(new
MarkerOptions().position(point).title(point.toString()));
markerClicked = false;
}
#Override
public boolean onMarkerClick(Marker marker) {
if(markerClicked){
if(polygon != null){
polygon.remove();
polygon = null;
}
polygonOptions.add(marker.getPosition());
polygonOptions.strokeColor(Color.RED);
polygonOptions.fillColor(Color.BLUE);
polygon = myMap.addPolygon(polygonOptions);
}else{
if(polygon != null){
polygon.remove();
polygon = null;
}
polygonOptions = new PolygonOptions().add(marker.getPosition());
markerClicked = true;
}
return true;
}
}
add this code to your onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
.
.
.
// define point to center on
LatLng origin = new LatLng(40.67, -73.94);
CameraUpdate panToOrigin = CameraUpdateFactory.newLatLng(origin);
myMap.moveCamera(panToOrigin);
// set zoom level with animation
myMap.animateCamera(CameraUpdateFactory.zoomTo(14), 400, null);
}
After the onClikListener are setted (into onCreate), put this code
LatLng NewYork= new LatLng(40.714623,-74.006605);
CameraPosition camPos = new CameraPosition.Builder().target(NewYork).zoom(14).build();
CameraUpdate cam = CameraUpdateFactory.newCameraPosition(camPos);
myMap.animateCamera(cam);
It will animate your map and move the camera to NY

Categories

Resources