Currently, I detect when user tap on Google Map maker as follow:
mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
// ---- copy to clipbored
copyToClip(marker.getSnippet());
return false;
}
});
However, I would prefer to detect when user tab on the "title" or snippet of the map marker (instead of the marker itself).
Is there a way to do that?
Try this code..
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
// TODO
}
});
Related
hi i dont know java but i have a homework and i'm trying to make a aapp with android studio its a map app i can add markerListener to markers but same happening ing every marker i want to give unique markerListener to all of my markers. I would be very glad if you help (my code)
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng Bodrum = new LatLng(37.034407, 27.430540);
LatLng UgurMosque = new LatLng(37.033124, 27.434417);
LatLng ABC = new LatLng(36.033124, 28.434417);
Marker ugur=mMap.addMarker(new MarkerOptions().position(UgurMosque)
.title("1")
);
Marker abc=mMap.addMarker(new MarkerOptions().position(ABC)
.title("2")
);
mMap.moveCamera(CameraUpdateFactory.newLatLng(Bodrum));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
String markertitle=marker.getTitle();
Intent i=new Intent(MapsActivity.this, DetailsActivity.class);
i.putExtra("title",markertitle);
startActivity(i);
return false;
}
});
Use Marker tags instead of title, tags are set by you and are predefined identifiers
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
String markertag =marker.getTag().toString();
if(markertag.equals("tag1")){
}
return false;
}
});
You can use a switch-case statement instead
To add markers use
mMap.addMarker("tag1", lattitude, longitude);
I am trying to center the marker's info window because it's fully visible. There are two images showing the problem. On the first the title of the info window is not visible and on the second image is how it should look like. Here is my code:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(final Marker marker) {
LatLng markerLocation = marker.getPosition();
Point mappoint = mMap.getProjection().toScreenLocation(new LatLng(markerLocation.latitude, markerLocation.longitude));
mappoint.set(mappoint.x, mappoint.y - 100);
CameraUpdate cu = CameraUpdateFactory.newLatLng(mMap.getProjection().fromScreenLocation(mappoint));
mMap.animateCamera(cu, new GoogleMap.CancelableCallback() {
#Override
public void onFinish() {
if (marker != null)
marker.showInfoWindow();
}
#Override
public void onCancel() {
}
});
return false;
}
});
The problem was the line:
returning false;
Should be:
returning true;
I am placing multiple markers on google map by using onMarkerClickListener, now I want to give user the option to remove any marker from the added markers. Can anyone suggest some way to do this.
my code for marker is
GoogleMap.OnMarkerClickListener listener = new
GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(final Marker marker) {
AddGeofenceFragment dFragment = new AddGeofenceFragment();
// Show DialogFragment
dFragment.show(fm, "Dialog Fragment");
return true;
}
};
newmap.setOnMarkerClickListener(listener);
newmap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
// This will be displayed on taping the marker
markerOptions.title(latLng.latitude + " : " + latLng.longitude);
// Animating to the touched position
newmap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
// Placing a marker on the touched position
newmap.addMarker(markerOptions);
Log.d("ADDED LATITUDE",String.valueOf(latLng.latitude));
Log.d("ADDED LONGITUDE",String.valueOf(latLng.longitude));
Toast.makeText(getApplicationContext(),"Block area updated",Toast.LENGTH_LONG).show();
}
});
you can do this by implementing interface OnMarkerClickListener to the mapActivity. then you need to write your require code to delete the selected marker in the method:
#Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(myMarker)) {
//handle click here
marker.remove();
}
}
I have application with google map v2 containing couple of MarkerOptions inside it. Is there a way to catch tap on info box that is opened after pin is tapped?
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
// do something
}
});
Probably duplicate question.
Try out as below:
GoogleMap mMap;
Marker myMarker= mMap.addMarker(new MarkerOptions()
.position(lng)
.title("Head Quarter Office")
.snippet("Delhi")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon)));
mMap.setOnMarkerClickListener(new OnMarkerClickListener()
{
#Override
public boolean onMarkerClick(Marker arg0) {
if(arg0.getTitle().equals("Marker")) // if marker source is clicked
Toast.makeText(MainActivity.this, arg0.getTitle(),1000).show();// display toast
return true;
}
});
I want to display like this.
https://lh6.ggpht.com/DOvS0NiHGyGC9Vn7JvkwznRBZ7I65j3zwpNAqLkP5y083ju7JQbwWi4NAXQLp5Wsavmn=h900
When google map marker gets tap, text will display below. It can be drag up and down. I don't get how it has been done.
public class MapsActivity extends FragmentActivity
{
Googlemap gm;
gm = ((SupportMapFragment) (getSupportFragmentManager()
.findFragmentById(R.id.map))).getMap();
gm.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gm.setOnInfoWindowClickListener(this);
#Override
public void onInfoWindowClick(Marker marker) {
String a=marker.getTitle();
// how to display this title in same screen below with dragging up and down when map marker been tap
}
}
Please help me to solve this issue.Thanks in advance.
implement this method instead of infoWindowClick
gm.setOnMarkerClickListener(new OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
String title = "Any Thing You want";
marker.setTitle(title);
textView.setText("title");
return true;
}
});
You have to create hidden layout for it. Create one layout as per your need and do it GONE by default. But when you click like below and inflate that layout in you onClick method:
gm.setOnInfoWindowClickListener(this);
#Override
public void onInfoWindowClick(Marker marker) {
String a=marker.getTitle();
LayoutInflater inflater;
inflater = LayoutInflater.from(context);
View view;
view = adapterInflater.inflate(R.layout.adapter_add_event, null);
// how to display this title in same screen below with dragging up and down when map marker been tap
}
And visible this layout, do findViewById and make it visible.
or.. If your marker is draggable, use the following snippet
map.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
#Override
public void onMarkerDragEnd(Marker marker) {
marker.setSnippet("Your Text");
map.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
}
});