Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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 Can';t在圆的中心解析mLatLng_Android_Google Maps - Fatal编程技术网

Android Can';t在圆的中心解析mLatLng

Android Can';t在圆的中心解析mLatLng,android,google-maps,Android,Google Maps,在我的Android地图中,我只需画一个圆圈,我需要将当前位置作为圆圈的中心,当更改设备的位置时,必须重新更改圆圈,并在圆圈内再次加载标记 这是我的密码 首先,我只是硬编码了大约5个位置 LatLng POINTA = new LatLng(6.9192, 79.8950); LatLng POINTB = new LatLng(6.9006, 79.8533); LatLng POINTC = new LatLng(6.9147, 79.8778); LatLng POINTD = new L

在我的Android地图中,我只需画一个圆圈,我需要将当前位置作为圆圈的中心,当更改设备的位置时,必须重新更改圆圈,并在圆圈内再次加载标记

这是我的密码

首先,我只是硬编码了大约5个位置

LatLng POINTA = new LatLng(6.9192, 79.8950);
LatLng POINTB = new LatLng(6.9006, 79.8533);
LatLng POINTC = new LatLng(6.9147, 79.8778);
LatLng POINTD = new LatLng(6.9036, 79.9547);
LatLng POINTE = new LatLng(6.8397, 79.8758);
这是我画圆圈和负载标记的地方

public static boolean isMyLocationSet = false; // Get Current location ass default location

@Override
public void onMyLocationChange(Location location) {

    isMyLocationSet=false; // Get Current location ass default location

    Location target = new Location("target");

    for(LatLng point : new LatLng[]{POINTA,POINTB,POINTC,POINTD,POINTE}){

        mMap.setMyLocationEnabled(true);
        mMap.setOnMyLocationChangeListener(this);

        LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = mLocationManager.getBestProvider(criteria, true);
        Location currentLocation = mLocationManager.getLastKnownLocation(provider);

        double latitude = location.getLatitude();

        double longitude = location.getLongitude();

        LatLng mLatLng = new LatLng(latitude, longitude);

        Circle circle = mMap.addCircle(new CircleOptions()
                .center(new LatLng(mLatLng))
                .radius(10000)
                .strokeColor(Color.BLUE)
                .strokeWidth(2));


        target.setLatitude(point.latitude);
        target.setLongitude(point.longitude);

        Marker marker = mMap.addMarker(new MarkerOptions()
                .position(new LatLng(point.latitude, point.longitude))
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));

        float[] distance = new float[2];

        if(location.distanceTo(target) <  10000) {
            marker.setVisible(true);
        }

        else {
            marker.remove();
        }


    }

}
公共静态布尔值isMyLocationSet=false;//获取当前位置和默认位置
@凌驾
公共void onMyLocationChange(位置){
isMyLocationSet=false;//获取当前位置作为默认位置
位置目标=新位置(“目标”);
for(LatLng点:新LatLng[]{POINTA、POINTB、POINTC、POINTD、POINTE}){
mMap.setMyLocationEnabled(真);
mMap.setOnMyLocationChangeListener(这个);
LocationManager MLLocationManager=(LocationManager)getSystemService(LOCATION\u服务);
标准=新标准();
字符串提供程序=mLocationManager.getBestProvider(条件为true);
Location currentLocation=mlLocationManager.getLastKnownLocation(提供程序);
双纬度=location.getLatitude();
double longitude=location.getLongitude();
LatLng mLatLng=新LatLng(纬度、经度);
圆圈=mMap.addCircle(新圆圈选项()
.中心(新车床(mLatLng))
.半径(10000)
.strokeColor(颜色.蓝色)
.冲程宽度(2);
目标设置纬度(点纬度);
设置经度(点经度);
Marker Marker=mMap.addMarker(新MarkerOptions()
.位置(新车床(点纬度、点经度))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
浮动[]距离=新浮动[2];
if(位置距离(目标)<10000){
marker.setVisible(true);
}
否则{
marker.remove();
}
}
}
这里我无法在
中心解析mLatLng(新LatLng(mLatLng))
它说

Latlng中的Latlng(double,double)不能应用于(com.google.andrdoid.gms.maps.model.Latlng)


我应该怎么做?代码中有什么地方我做错了吗?

您将LatLng对象放在createnewlatlng类对象中

因此,对于这种类型的消息,请仅使用对象作为参数


center()。Thnaks.)
LatLng mLatLng = new LatLng(latitude, longitude);

Circle circle = mMap.addCircle(new CircleOptions()
            .center(mLatLng)
            .radius(10000)
            .strokeColor(Color.BLUE)
            .strokeWidth(2));
Circle circle = mMap.addCircle(new CircleOptions()
            .center(new LatLng(latitude, longitude))
            .radius(10000)
            .strokeColor(Color.BLUE)
            .strokeWidth(2));