简体   繁体   中英

How to allow the user to place their own pin google maps api V2 with android sdk(JAVA)

如何允许用户在Google地图上的任意位置放置或拖动自定义标记(例如图片)?

If you want to make your user able to set a custom location in your Map, you can achieve it by doing the following:

  1. Your activity / fragment has to implement the OnMapClickListener interface
  2. Set your map listener like this: myMap.setOnMapClickListener(this);
  3. Implement public void onMapClick(LatLng point) which is the method you have to implement in step 1.
  4. Get the LatLong position from this method and place your marker in that point.

Like this:

MarkerOptions options=new MarkerOptions().snippet(getString(R.string.snippet))
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.mymarker))
        .anchor(0.5f, 0.5f);
options.position(point);
myMap.addMarker(options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM