0
我想在地圖上建立一個指定半徑的圓圈,就像 RadPad Apple應用程序。在android中地圖內建立一個圓圈
的想法是,圓保持固定的,但是用戶可以移動地圖。 在圓圈內我想計算位於其半徑內的所有標記。
我想在地圖上建立一個指定半徑的圓圈,就像 RadPad Apple應用程序。在android中地圖內建立一個圓圈
的想法是,圓保持固定的,但是用戶可以移動地圖。 在圓圈內我想計算位於其半徑內的所有標記。
這對我有用。
在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);
}
你嘗試過什麼?你有地圖視圖,你已經在使用嗎?你是否研究過如何在視圖中繪製圓圈? – 2014-09-04 08:05:15
我不知道如何解決這個問題,但我正在處理地圖,所以我可以告訴你:你必須在地圖中定義「圓圈」是什麼。因爲地圖使用了投影,所以如果您告訴圓是與另一個點(中心)具有相同距離的點的軌跡,則它不是地圖中的完美圓。您必須首先考慮投影類型,以及您打算作爲半徑的多大距離(大圓圈,斜線)。你可以在這裏看到一個例子:http://braincrunch.tumblr.com/post/23672142073/mercators-egg – Jepessen 2014-09-04 08:43:31