通过网址在Google Maps v2 Android上设置标记图标 [英] Set marker icon on Google Maps v2 Android from URL
问题描述
我无法将Google Places API提供的图标添加到标记中.例如,我想让图标从Google Places API的JSON返回:
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"
这是我现在不添加图标的方式:
for (Place place : mNearPlaces.results) {
LatLng placeLatLng = new LatLng(place.geometry.location.lat,
map.addMarker(new MarkerOptions()
.position(placeLatLng)
.title(place.name));
}
我查看了这篇文章和建议使用一些AsyncTask来下载图像.还有其他方法可以做到这一点(这种方法似乎很慢)?是否有设置Google Places API提供的标记图像的标准方法?
这是用于标记的Google Maps Android API v2文档 >
谢谢
您好,可以使用库来帮助您从URL查看图像.访问 https://github.com/nostra13/Android-Universal-Image-Loader适用于 Android通用图像加载器
您也可以访问了解有关下载图像的信息
http://brainflush .wordpress.com/2009/11/23/droid-fu-part-2-webimageview-and-webgalleryadapter/
然后是
对于自定义标记图标",您可以使用图标来显示为标记.从任何受支持的来源中加载图标.
fromAsset(String assetName)–从资产文件夹加载
fromBitmap(位图图像)–加载位图图像
fromFile(字符串路径)–从文件加载
fromResource(int resourceId)–从可绘制资源加载
尝试如下
// latitude and longitude
double latitude = 17.385044;
double longitude = 78.486671;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon)));
// adding marker
googleMap.addMarker(marker);
I am unable to add the icon provided by the Google Places API to the marker. For example, I would like to have the icon returned from the JSON of Google Places API:
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"
Here's how I am doing it now without adding the icon:
for (Place place : mNearPlaces.results) {
LatLng placeLatLng = new LatLng(place.geometry.location.lat,
map.addMarker(new MarkerOptions()
.position(placeLatLng)
.title(place.name));
}
I looked at this post and the answer suggested using some AsyncTask to download the image. Is there any other way to do this (that way seems slow)? Is there a standard way of setting the marker image provided by the Google Places API?
Here is the Google Maps Android API v2 Documentation for Markers
Thanks
Hi use a librariy that help you to view images from URL. visit https://github.com/nostra13/Android-Universal-Image-Loader for Android-Universal-Image-Loader
also you can visit to know for downloading the image
http://brainflush.wordpress.com/2009/11/23/droid-fu-part-2-webimageview-and-webgalleryadapter/
and after that
for the Custom Marker Icon, you can use an icon to show as a marker. load the icon from any kind of supported sources.
fromAsset(String assetName) – Loading from assets folder
fromBitmap (Bitmap image) – Loading bitmap image
fromFile (String path) – Loading from file
fromResource (int resourceId) – Loading from drawable resource
try as follows
// latitude and longitude
double latitude = 17.385044;
double longitude = 78.486671;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon)));
// adding marker
googleMap.addMarker(marker);
这篇关于通过网址在Google Maps v2 Android上设置标记图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!