谷歌地图API V2从URL的Android添加图标 [英] google map api v2 add icon from url android
本文介绍了谷歌地图API V2从URL的Android添加图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从Web服务获取经纬度一个项目,我将它们添加到谷歌地图标记。我想添加自定义图标从URL标记。
mMap.addMarker(新的MarkerOptions()
.POSITION(新经纬度(DLAT,Dlong))
.title伪(m.group(9))
.draggable(假)
是.snippet(m.group(1)++ m.group(10)));
我如何添加 .icon
从一个链接的自定义图标?
解决方案
使用此方法和用途返回位在地图中显示公共位图getBitmapFromURL(字符串图片网址){
尝试{
网址URL =新的URL(图片网址);
HttpURLConnection的连接=(HttpURLConnection类)url.openConnection();
connection.setDoInput(真);
connection.connect();
输入的InputStream = connection.getInputStream();
位图MYBITMAP = BitmapFactory.de codeStream(输入);
返回MYBITMAP;
}赶上(IOException异常五){
e.printStackTrace();
返回null;
}
}
I have a project that retrieves latitude and longitude from web service and I add them to google map markers. I want to add custom icon for the markers from url.
mMap.addMarker(new MarkerOptions()
.position(new LatLng(dlat,Dlong))
.title(m.group(9))
.draggable(false)
.snippet(m.group(1)+" "+m.group(10)));
How I can add .icon
with a custom icon from a link?
解决方案
Use this method and use returned bitmap to display in map
public Bitmap getBitmapFromURL(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
这篇关于谷歌地图API V2从URL的Android添加图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文