我已经在Android的谷歌地图上放置了一个标记,我想要做的就是当它被触摸一个图像显示在它上面,标记停留在那里,标题,片段等以及图像显示器。我一直在网上搜索,找不到任何解决方案。也可以在图像出现时,如果用户点击它,则执行例如动作。转到另一页,放大图像等。
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
感谢。
答案 0 :(得分:0)
Googel Map With coustem image
mSydney = mMap.addMarker(new MarkerOptions()
.position(SYDNEY)
.title("Sydney")
.snippet("Population: 4,627,300")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
以及
private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
private Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
答案 1 :(得分:0)
您必须使用Android Utils将图片放置在标记为Google地图的地方。请查看此链接以获取完整的code。
public class IconGeneratorDemoActivity extends BaseDemoActivity {
@Override
protected void startDemo() {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10));
IconGenerator iconFactory = new IconGenerator(this);
addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094));
iconFactory.setStyle(IconGenerator.STYLE_BLUE);
addIcon(iconFactory, "Blue style", new LatLng(-33.9360, 151.2070));
iconFactory.setRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_RED);
addIcon(iconFactory, "Rotated 90 degrees", new LatLng(-33.8858, 151.096));
iconFactory.setContentRotation(-90);
iconFactory.setStyle(IconGenerator.STYLE_PURPLE);
addIcon(iconFactory, "Rotate=90, ContentRotate=-90", new LatLng(-33.9992, 151.098));
iconFactory.setRotation(0);
iconFactory.setContentRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_GREEN);
addIcon(iconFactory, "ContentRotate=90", new LatLng(-33.7677, 151.244));
}
private void addIcon(IconGenerator iconFactory, String text, LatLng position) {
MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).
position(position).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());
getMap().addMarker(markerOptions);
}
}
答案 2 :(得分:0)
您可以使用自定义图片作为标记
否则您需要设置标记侦听器,并且需要添加另一个视图以显示展开的图像或您需要执行的任何其他...
public mapActivity extends Activity implements OnMarkerClickListener{
public GoogleMap mMap;
mMap.setOnMarkerClickListener(this);
@Override
public boolean onMarkerClick(Marker marker) {
//Here you can show your own view to display image
//else you can call another activity etc...
}
}
答案 3 :(得分:0)
在代码中添加自定义InfoWindow标记:
class MyInfoWindowAdapter implements InfoWindowAdapter {
private final View myContentsView;
MyInfoWindowAdapter() {
myContentsView = getLayoutInflater().inflate(R.layout.map_popup,
null);
}
@Override
public View getInfoContents(Marker marker) {
TextView tvTitle = ((TextView) myContentsView
.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
TextView tvSnippet = ((TextView) myContentsView
.findViewById(R.id.snippet));
ImageView ivIcon = ((ImageView) myContentsView
.findViewById(R.id.icon));
tvSnippet.setText(marker.getSnippet());
return myContentsView;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}
@Override
public void onInfoWindowClick(Marker arg0) {
Toast.makeText(GoogleMapActivity.this, "Marker Info Window clicked",
Toast.LENGTH_SHORT).show();
}
在你的onCreate()方法中,添加以下行:
googleMap.setInfoWindowAdapter(new MyInfoWindowAdapter());