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