我想在地图上建立一个具有指定半径的圆圈 RadPad Apple应用程序。
这个想法是圆圈保持固定但用户可以移动地图。 在圆圈内我想要计算位于其半径内的所有标记。
答案 0 :(得分:0)
这对我有用。
在xml布局中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
在Main.java中
public class Main extends ActionBarActivity{
private GoogleMap gmap;
private LatLng exact_location;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locations_layout);
exact_location = new LatLng(LAT,LONG);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
gmap = mapFragment.getMap();
gmap.moveCamera(CameraUpdateFactory.newLatLngZoom(exact_location,15));
gmap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
gmap.animateCamera(CameraUpdateFactory.zoomTo(10), null);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(exact_location) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(85) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
gmap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
CircleOptions circleOptions = new CircleOptions().center(exact_location)
.strokeColor(Color.RED)
.radius(1000); // In meters
gmap.addCircle(circleOptions);
}