Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android的google map v2中查找多边形区域_Android_Maps - Fatal编程技术网

在android的google map v2中查找多边形区域

在android的google map v2中查找多边形区域,android,maps,Android,Maps,我制作了一个android应用程序,显示谷歌地图,在地图上我画了一个多边形,其LatLng存储在arrayList中。。我想找到谷歌地图上绘制的多边形的面积,我已经尽了最大努力,但没有成功,我无法使用Sphere util,compute area函数,因为它会出错,请为我提供最好的帮助 提前感谢,我在下面提供我的代码,请建议如何找到多边形的面积,正在绘制。。。谢谢 dpackage com.example.mapss; import java.util.ArrayList; import

我制作了一个android应用程序,显示谷歌地图,在地图上我画了一个多边形,其LatLng存储在arrayList中。。我想找到谷歌地图上绘制的多边形的面积,我已经尽了最大努力,但没有成功,我无法使用Sphere util,compute area函数,因为它会出错,请为我提供最好的帮助

提前感谢,我在下面提供我的代码,请建议如何找到多边形的面积,正在绘制。。。谢谢

dpackage com.example.mapss;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.android.gms.maps.model.PolylineOptions;

public class MainActivity extends Activity {


GoogleMap map;
ArrayList<LatLng> arrayPoints =null;
PolylineOptions polylineOptions;
PolygonOptions polygonOptions;
RadioGroup rg_views;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    arrayPoints = new ArrayList<LatLng>();

    map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.getUiSettings().setZoomControlsEnabled(true);
    map.getUiSettings().setCompassEnabled(true);
    map.getUiSettings().setMyLocationButtonEnabled(true);

    map.setMyLocationEnabled(true);

    rg_views =(RadioGroup)findViewById(R.id.rg_views);
    rg_views.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub

            if (checkedId==R.id.rb_map){
                map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

            }
            else if(checkedId==R.id.rb_satellite){
                map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

            }
            else if(checkedId==R.id.rb_terrain){
                map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            }

        }
    });

    map.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            // TODO Auto-generated method stub

            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.position(point);

            markerOptions.title(point.latitude + ": " + point.longitude);

            map.clear();

            map.animateCamera(CameraUpdateFactory.newLatLng(point));


            map.addMarker(markerOptions);

            polygonOptions = new PolygonOptions();
            polygonOptions.fillColor(Color.RED);
            polygonOptions.strokeWidth(5);
            arrayPoints.add(point);
            polygonOptions.addAll(arrayPoints);
            map.addPolygon(polygonOptions);



        }
    });

    map.setOnMapLongClickListener(new OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng point) {
            // TODO Auto-generated method stub

            map.clear();
            arrayPoints.clear();

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}
dpackage com.example.mapss;
导入java.util.ArrayList;
导入android.annotation.SuppressLint;
导入android.app.Activity;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.widget.RadioGroup;
导入android.widget.RadioGroup.OnCheckedChangeListener;
导入com.google.android.gms.maps.CameraUpdateFactory;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.GoogleMap.OnMapClickListener;
导入com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
导入com.google.android.gms.maps.MapFragment;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
导入com.google.android.gms.maps.model.polygonooptions;
导入com.google.android.gms.maps.model.PolylineOptions;
公共类MainActivity扩展了活动{
谷歌地图;
ArrayList arrayPoints=null;
多段线选项多段线选项;
多克隆选择;
放射组RGU视图;
@SuppressLint(“新API”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arrayPoints=新的ArrayList();
map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.map\u TYPE\u NORMAL);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(true);
map.setMyLocationEnabled(true);
rg_视图=(放射组)findViewById(R.id.rg_视图);
rg_views.setOnCheckedChangeListener(新的OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(RadioGroup组,int checkedId){
//TODO自动生成的方法存根
if(checkedId==R.id.rb\u映射){
map.setMapType(GoogleMap.map\u TYPE\u NORMAL);
}
else if(checkedId==R.id.rb_卫星){
map.setMapType(谷歌地图.map_类型_卫星);
}
else if(checkedId==R.id.rb\U地形){
setMapType(GoogleMap.map\u TYPE\u HYBRID);
}
}
});
setOnMapClickListener(新的OnMapClickListener(){
@凌驾
公共空区(停车点){
//TODO自动生成的方法存根
MarkerOptions MarkerOptions=新MarkerOptions();
标记选项。位置(点);
标记选项.标题(点.纬度+:“+点.经度);
map.clear();
map.animateCamera(CameraUpdateFactory.newLatLng(point));
map.addMarker(markerOptions);
polygonOptions=新的polygonOptions();
多边形选项。填充颜色(颜色。红色);
脉冲宽度(5);
数组点。添加(点);
polygonooptions.addAll(数组点);
添加多边形(多边形选项);
}
});
setOnMapLongClickListener(新的OnMapLongClickListener(){
@凌驾
在马普隆喀喇克(LatLng点)上的公共空隙{
//TODO自动生成的方法存根
map.clear();
arrayPoints.clear();
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}

谷歌地图Api支持库与我配合良好
要使用computeArea方法,您需要导入

com.google.maps.android.SphericalUtil
就我而言,我是照例进口的。 然后你可以打电话

SphericalUtil.computeArea(listOfLatLng)

你应该使用这个函数

com.google.maps.android.SphericalUtil;
public static double computeArea(java.util.List<LatLng> path)

查看此链接了解更多功能

这并不能回答问题。请仔细阅读这个问题。问题不是如何判断一个点是否在多边形内,而是如何计算多边形的面积。Tim是对的,我想知道如何计算绘制在地图上的多边形面积…另请参见此处:
compile 'com.google.maps.android:android-maps-utils:0.5+'