Android Google Map to show as picture(Android谷歌地图显示为图片)
问题描述
我已经在我的 Android 应用中实现了 Google Maps V2,现在我想做一些不同的事情.我正在用标记显示一个位置(经度、纬度).问题是这在我的活动中显示为地图.我想将它显示为 ImageView,并且只有当有人点击它时才会显示地图界面.
I've implemented Google Maps V2 in my android app and now I would like to do something differently. I'm showing a location (longitude, latitude) with a marker. The problem is that this is showing in my activity as a Map. I would like to show it as a ImageView and only if someone clicks on it show the map interface.
基本上我想要做的是位置的静态预览并将其显示为图片(带有框架和圆角)单击时打开地图并提供所有功能.
Basically what I want to do is a static preview of the location and display it as a picture (with a frame and rounded corners) When clicked then open maps and give all functionality.
有没有办法将地图片段放入 ImageView 中?
Is there a way to put a map fragment into a ImageView?
您能提供的任何帮助将不胜感激.
Any help you can provide will greatly appreciated.
谢谢
推荐答案
您可以使用 Google Maps 内置的快照方法,捕获预览并将其显示在 ImageView
中.您可以以任何您喜欢的方式设置 ImageView
的样式,还可以设置一个 clickListener 在单击预览时执行某些操作.这是一个例子:
You can use the Google Maps built-in snapshot method, to capture a preview and display it in an ImageView
. You can style the ImageView
in any way you like, and also set a clickListener that does something, when the preview is clicked. Here's an example:
LatLng latLng = new LatLng(35.0116363, 135.7680294);
// Add Marker
mMap.addMarker(new MarkerOptions().position(latLng));
// Center map on the marker
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(latLng, 4.0f);
mMap.animateCamera(yourLocation);
final ImageView mapPreview = (ImageView) findViewById(R.id.mapPreview);
mapPreview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Hide the preview, to reveal the map
mapPreview.setImageBitmap(null);
mapPreview.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
// Or start Google Maps app
// String uri = String.format(Locale.ENGLISH, "geo:%f,%f", 50.0, 0.1);
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
// startActivity(intent);
}
});
mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
// Make a snapshot when map's done loading
mMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
mapPreview.setLayoutParams(new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mapPreview.setImageBitmap(bitmap);
// If map won't be used afterwards, remove it's views
// ((FrameLayout)findViewById(R.id.map)).removeAllViews();
}
});
}
});
这篇关于Android谷歌地图显示为图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android谷歌地图显示为图片
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01