簡體   English   中英

在Android的地圖內建立一個圓圈

[英]Build a circle inside the map in android

我想在地圖上建立一個具有指定半徑的圓,就像RadPad Apple應用程序一樣。

在此處輸入圖片說明

這個想法是圓圈保持固定,但用戶可以移動地圖。 在圓內,我想計算位於圓內的所有標記。

這對我有效。

在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);
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM