I am an android fresh man and developing a small app with Google Map V2.
I want to get the WGS84 (i.e. LatLng)position when longpress on the MAP.
Several methods are tried as the answers in other topic but the longpress guesture still could not be detected.
Can anyone help on this to provide some sample code for me?
Have you tried this?
mMap.setOnMapLongClickListener(new OnMapLongClickListener() {
#Override
public void onMapLongClick(final LatLng point) {
}
});
Related
I have built a music app and now I am trying to build a mapping feature more like Shazam's or Instagrams as follows:
Where initially, I am to drop a general marker on several points without actually showing all the activity in that location. Then on tapping that marker, the map will zoom in and other markers that are more specific will show, and so on..
Is there a tutorial available that I can follow the to achieve this effect in Android?
I have just found out that Google has a utility library that provides for marker clustering. The documentation can be found here https://developers.google.com/maps/documentation/android-api/utility/marker-clustering
You can create a method to add custom markers using this function:
private void drawCustomMarker(LatLng point) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.title("SMS");
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.sms));
mMap.addMarker(markerOptions);
}
You can pass LatLng object where you want to drop the marker. I have used it in map click listener:
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng newlatLng) {
drawCustomMarker(newlatLng);
}
});
Hope it will help you..!
I am working with Google Maps Android API V2.
When my map fragment is loaded it shows my location automatically (with the blue dot). Why does this happen? Is my location history affecting or is the default working mode?
Does this code cause it?:
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
googleMap.setOnMyLocationChangeListener(null);
}
});
I have commented this piece of code but the map is still showing the blue dot.
If this is not happening because of the history, would this piece of code be enough to get user location or do I need to use LocationManager class as described in other questions?
Try to use
googleMap.setMyLocationEnabled(true/false);
to control showing your location on map. I think it is enough to turn the setting on to make your location work with Google Maps, without need to use LocationManager etc.
i have some problems creating route directionns on the nutiteq map from MapQuestApi, i Know how to Receive the Information needed
#Override
public void onSuccess(RouteResponse routeResponse) {
clearButton.setVisibility(View.VISIBLE);
if(showItineraryButton.getVisibility()==View.GONE &&
showMapButton.getVisibility()==View.GONE){
showItineraryButton.setVisibility(View.VISIBLE);
}
createRouteButton.setEnabled(true);
}
});
but i dont know how to use them to create route lines on them nutiteq map, and appearantly its demo sample doesnt say any thing, it has a RouteActivity Interface which does not exists any where in the Sample Codes, if any one has done this , can some one please show me how can i "draw" the route points using received information ? i would really appreciate
The RouteActivity is in separate project AdvancedLayers.
From MapQuestRouteActivity.java in AdvancedMap3D project you can find method public void routeResult(Route route) which is called from MapQuestDirections.java (source is also in AdvancedLayers). The MapQuestDirections has already parsed routing result and created a line (which is part of the Route) which can be added to the map.
Hi I am working on google maps and more specifically on setting some markers when the user clicks on the map. The problem is that whenever I re-run the activity or re-compile the application the markers disappear from the map. Any advice on that. Please help. Thank you
Here is my code where the markers are created on the onmapclick event.
gMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng position) {
gMap.addMarker(new MarkerOptions().position(position)
.title("BAR")
.snippet("DRINKS")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
}
});
}
Think of Markers as you think of of Android Views. If you re-run the application, user and password EditTexts that were previously entered are not filled anymore.
Use some kind of persistance to achive it. Check out your storage options here.
I'm using Google Maps v2 in an Android application that I'm writing. After creating the map and adding all the markers to it, I make all the markers draggable by using marker.setDraggable(true); for each marker on the map.
If I run the code like this, the markers are indeed draggable. However, I'd like to change the icon or color of the marker while it's being dragged, so I set up an OnMarkerDragListener, like so:
map.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
#Override
public void onMarkerDragStart(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
}
#Override
public void onMarkerDrag(Marker marker) {
}
#Override
public void onMarkerDragEnd(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker());
}
});
After adding in that block of code, though, the markers are no longer draggable. The color successfully changes in both the onMarkerDragStart and onMarkerDragEnd methods, but that's it. Can anyone explain what I'm doing wrong here, and why the markers aren't getting dragged ?
i would say that the problem comes from changing the icon rather than from settings the listener.
Please note that Marker.setIcon is not a function that is available in all the versions of the GoogleMaps V2 API. This means that probably it is not available in the library you have, or in the version of the play services installed in the device in which you are trying your app, and that could be causing any kind of malfunction.
As you can read here that function was added in May 2013. Please try updating everything, the google-play-services_lib, and the play services installed in the device.
If this happen to fix it, then you can try to change the icon only depending on the version installed on the mobile.