我看到人们在这项具体任务中遇到很多困难,我也需要帮助。
我已使用Google提供的默认代码在地图上成功创建了标记。但现在我希望能够点击“InfoWindow”打开一个新活动,以便我可以添加更多信息。
从这个标题和摘录的基本标记:
http://mobisys.in/blog/wp-content/uploads/2013/04/Screenshot_2013-04-04-17-19-581.png
然后点击它并打开一个空白活动:
有谁知道最好的方法吗?
如果你能回答这个 ,请提供一些代码或示例。 任何帮助将不胜感激!
答案 0 :(得分:56)
将此添加到您的代码
Mymap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapActivity.this,OtherActivity.class);
startActivity(intent);
}
});
答案 1 :(得分:1)
This method works even well with multiple markers. get the title of the marker using marker.getTitle() and Starts the activity based on which marker you clicked.
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng chennai = new LatLng(12.9671, 80.2593);
mMap.addMarker(new MarkerOptions().position(chennai).title("Chennai"));
LatLng perungudi = new LatLng(12.97, 80.25);
mMap.addMarker(new MarkerOptions().position(perungudi).title("Perungudi"));
LatLng pallikarnai = new LatLng(12.9377, 80.2154);
mMap.addMarker(new MarkerOptions().position(pallikarnai).title("Pallikarnai"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chennai,12));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTitle().equals("Chennai")){
Toast.makeText(MapsActivity.this, "Clicked"+marker.getTitle(), Toast.LENGTH_SHORT).show();
}
return false;
}
});
}