如何允许用户在Android中选择Google地图上的区域?用例子

时间:2015-07-14 09:14:08

标签: android google-maps

这是我添加标记和圆圈的代码

我想为用户提供一个功能,他可以相应地增加该圆的半径,为此我给了一个条,当用户增加该条时,圆的半径将增加,反之亦然。

    googleMap.setOnMapClickListener(new OnMapClickListener() {



        @Override
        public void onMapClick(final LatLng point) {



            // Drawing marker on the map

/ *

* /

         // Creating a marker
            MarkerOptions markerOptions = new MarkerOptions();

            // Setting the position for the marker
            markerOptions.position(point);

            // Setting the title for the marker.
            // This will be displayed on taping the marker
            markerOptions.title(point.latitude + " : " + point.longitude);

            // Clears the previously touched position
            googleMap.clear();

            // Animating to the touched position
            googleMap.animateCamera(CameraUpdateFactory.newLatLng(point));



            seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                int r=100;

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    // TODO Auto-generated method stub

                            googleMap.addCircle(new CircleOptions()
                            .center(new LatLng(point.latitude,point.longitude))
                            .radius(r)        
                            .strokeColor(Color.BLUE)//border color
                            .strokeWidth(3.0f)//border width
                            .fillColor(0x200000ff)
                            );



                }


            });

            // Placing a marker on the touched position
            googleMap.addMarker(markerOptions);


            Toast.makeText(getBaseContext(), "Your Choice Added ", Toast.LENGTH_SHORT).show();

        }
    });


});


}

}

1 个答案:

答案 0 :(得分:0)

此问题的解决方案将涉及地图叠加以及画布的组合。因此,一旦搜索条监听器检测到更改,它就可以指示地图叠加层增加或减小圆的大小。半径的变化将是画布的函数。有关代码实现,请参阅stack overflow解决方案。