Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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 无法添加多个圆和地图标记_Android_Google Maps_Android Geofence - Fatal编程技术网

Android 无法添加多个圆和地图标记

Android 无法添加多个圆和地图标记,android,google-maps,android-geofence,Android,Google Maps,Android Geofence,我正在创建一个geofence应用程序,它有一个地图界面供用户查看geofence的位置。我遇到的问题是,每当我加载坐标时,它只会绘制一个圆和一个标记,但地理围栏可以按预期输入和输出。目前,我没有物理设备可供测试,所以我依赖于模拟器 private void loadGeofencesFromDatabase() { for (Map.Entry<String, LatLng> entry : Constants.BAY_AREA_LANDMARKS.entrySet())

我正在创建一个geofence应用程序,它有一个地图界面供用户查看geofence的位置。我遇到的问题是,每当我加载坐标时,它只会绘制一个圆和一个标记,但地理围栏可以按预期输入和输出。目前,我没有物理设备可供测试,所以我依赖于模拟器

private void loadGeofencesFromDatabase() {

    for (Map.Entry<String, LatLng> entry : Constants.BAY_AREA_LANDMARKS.entrySet()) {

        mGeofenceList.add(new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this
                // geofence.
                .setRequestId(entry.getKey())

                // Set the circular region of this geofence.
                .setCircularRegion(
                        entry.getValue().latitude,
                        entry.getValue().longitude,
                        Constants.GEOFENCE_RADIUS_IN_METERS
                )

                // Set the expiration duration of the geofence. This geofence gets automatically
                // removed after this period of time.
                .setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)

                // Set the transition types of interest. Alerts are only generated for these
                // transition. We track entry and exit transitions in this sample.
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                        Geofence.GEOFENCE_TRANSITION_EXIT)

                // Create the geofence.
                .build());

        GeofenceLatLngCoordinates = new ArrayList<>();
        GeofenceLatLngCoordinates.add(new LatLng(entry.getValue().latitude, entry.getValue().longitude));

        GEOFENCE_RADIUS = Constants.GEOFENCE_RADIUS_IN_METERS;

        addGeofences();

    }
}


您正在创建
GeofenceLatLngCoordinates=new ArrayList()for
循环时的code>

只需将该行移到
for
循环之前:

private void loadGeofencesFromDatabase() {
    GeofenceLatLngCoordinates = new ArrayList<>();
    GEOFENCE_RADIUS = Constants.GEOFENCE_RADIUS_IN_METERS;

    for (Map.Entry<String, LatLng> entry : Constants.BAY_AREA_LANDMARKS.entrySet()) {
        mGeofenceList.add(new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this
                // geofence.
                .setRequestId(entry.getKey())

                // Set the circular region of this geofence.
                .setCircularRegion(
                        entry.getValue().latitude,
                        entry.getValue().longitude,
                        Constants.GEOFENCE_RADIUS_IN_METERS
                )

                // Set the expiration duration of the geofence. This geofence gets automatically
                // removed after this period of time.
                .setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)

                // Set the transition types of interest. Alerts are only generated for these
                // transition. We track entry and exit transitions in this sample.
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                        Geofence.GEOFENCE_TRANSITION_EXIT)

                // Create the geofence.
                .build());

        GeofenceLatLngCoordinates.add(new LatLng(entry.getValue().latitude, entry.getValue().longitude));
        addGeofences();
    }
}
private void loadgeofenssfromdatabase(){
GeofenceLatLngCoordinates=新的ArrayList();
土工围栏半径=常数。土工围栏半径(单位:米);
对于(Map.Entry:Constants.BAY\u AREA\u LANDMARKS.entrySet()){
mGeofenceList.add(new geofinence.Builder()
//设置地理围栏的请求ID。这是一个用于标识此项的字符串
//地球围栏。
.setRequestId(entry.getKey())
//设置此地理围栏的圆形区域。
.setCircularRegion(
entry.getValue().latitude,
entry.getValue()经度,
常数。土工围栏半径(单位:米)
)
//设置地理围栏的过期时间。此地理围栏将自动
//在这段时间后删除。
.setExpirationDuration(常数.geofense\u EXPIRATION\u以毫秒为单位)
//设置感兴趣的转换类型。仅为这些类型生成警报
//转换。我们在这个示例中跟踪进入和退出转换。
.setTransitionTypes(geofnce.geofnce\u TRANSITION\u输入|
土工围栏。土工围栏(过渡段和出口)
//创建地理围栏。
.build());
添加(新的LatLng(entry.getValue().latitude,entry.getValue().longitude));
添加地理围栏();
}
}
private void loadGeofencesFromDatabase() {
    GeofenceLatLngCoordinates = new ArrayList<>();
    GEOFENCE_RADIUS = Constants.GEOFENCE_RADIUS_IN_METERS;

    for (Map.Entry<String, LatLng> entry : Constants.BAY_AREA_LANDMARKS.entrySet()) {
        mGeofenceList.add(new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this
                // geofence.
                .setRequestId(entry.getKey())

                // Set the circular region of this geofence.
                .setCircularRegion(
                        entry.getValue().latitude,
                        entry.getValue().longitude,
                        Constants.GEOFENCE_RADIUS_IN_METERS
                )

                // Set the expiration duration of the geofence. This geofence gets automatically
                // removed after this period of time.
                .setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)

                // Set the transition types of interest. Alerts are only generated for these
                // transition. We track entry and exit transitions in this sample.
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                        Geofence.GEOFENCE_TRANSITION_EXIT)

                // Create the geofence.
                .build());

        GeofenceLatLngCoordinates.add(new LatLng(entry.getValue().latitude, entry.getValue().longitude));
        addGeofences();
    }
}