【发布时间】:2020-03-18 08:09:55
【问题描述】:
我无法使标记成为打开新活动的按钮,我正在从 GeoJson 文件中获取坐标信息,但能够获取标记但标记不会进入新活动。
我已尝试在某些查询中使用 setOnClickListener 和 setOnWindowClickListner,但无济于事
@Override
public void onMapReady(GoogleMap googleMap) {
// entering the google maps setting
googleMap.getUiSettings().setZoomControlsEnabled(true);
ArrayList<LatLng> listPoints = new ArrayList<LatLng>();
googleMap.setTrafficEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(Sg));
googleMap.setMinZoomPreference(11);
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e(TAG, "Style parsing failed.");
}
try {`//getting data from geojson`
getData();
JSONObject emptyGeoJson = new JSONObject();
layerShop = new GeoJsonLayer(googleMap, emptyGeoJson);
layerFB = new GeoJsonLayer(googleMap, emptyGeoJson);
layerComm = new GeoJsonLayer(googleMap, emptyGeoJson);
GeoJsonLayer layer = new GeoJsonLayer(googleMap, HotspotData);
Iterable<GeoJsonFeature> geoJsonFeature = layer.getFeatures();
for(GeoJsonFeature cur : geoJsonFeature) {
String s = cur.getProperty("Description");
int begin = s.indexOf("<th>LOCATION_TYPE</th> <td>");
int end = s.indexOf("</td>",begin);
String category = s.substring(begin+27,end);
if (category.contentEquals("F&B")){
layerFB.addFeature(cur);
Log.v("MapsActivity", "So here we are with " + cur);
}
else if (category.contentEquals("Shopping Mall")){
layerShop.addFeature(cur);
}
else if (category.contentEquals("Community")){
layerComm.addFeature(cur);
}
}
layers.put("Community", layerComm);
layers.put("Cafes", layerFB);
layers.put("Shopping", layerShop);
} catch (Exception e) {
e.printStackTrace();
}
GeoJsonPointStyle pointStyle = layerFB.getDefaultPointStyle();
pointStyle.setIcon(bitmapDescriptorFromVector(this, R.drawable.ic_wifi));
pointStyle.setTitle("View information");
//Log.v("MapsActivity", "This is layerFB + " + layerFB.getFeatures());
Iterable<GeoJsonFeature> layerFBfeature = layerFB.getFeatures();
Iterable<GeoJsonFeature> layerShopfeature = layerShop.getFeatures();
Iterable<GeoJsonFeature> layerCommfeature = layerComm.getFeatures();
Marker marker;
for(GeoJsonFeature i: layerFBfeature){
LatLng is = (LatLng)i.getGeometry().getGeometryObject();
marker = googleMap.addMarker(new MarkerOptions().position(is).title("location"));
}
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this, activity_location.class);
startActivity(intent);
return true;
}
});
}
【问题讨论】:
-
首先验证您的 on markerClickListener 是否正常工作,或者只是放置日志或 toast 消息,如果其片段使用 getActivity() 或 requireActivity() 来自 Intent,则不确定这是一个 Activity 或片段
标签: java android android-studio google-maps geojson