Search code examples
androidgoogle-mapsgoogle-maps-markersmarkertouch-event

Add Marker on Android Google Map via touch or tap


I want to develop a Map Application using Google Map on Android. Now, I want to add marker on the map via Touch or Tap on the Map. How do I apply touch event to drop the marker on the map?


Solution

  • This code is Successful run I am working on that code this code is for Dynamic Draw

    I think this code help you more for Static or dynamic both places you can use this code

    double latval = Double.parseDouble(jsonobject.getString("lat"));
    double longval = Double.parseDouble(jsonobject.getString("lon"));
    
    mMap.addMarker(new MarkerOptions()
                   .position(new LatLng( latval,    longval))
                   .title(jsonobject.getString("country"))
                   .snippet("4 E. 28TH Street From $15 /per night")
                   .rotation((float) -15.0)
                   .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
                  );
    
    if (i == 0) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                                    new LatLng(latval, longval), 7));
        mMap.addCircle(new CircleOptions()
                       .center(new LatLng(latval,longval))
                       .radius(5000)
                       .strokeColor(Color.RED)
                       .fillColor(Color.RED)); 
    }