如何在谷歌不同的标记不同的信息窗口中添加不同的图像地图API V2为Android [英] how to add different images in different information window for different markers in google maps api v2 for android

查看:235
本文介绍了如何在谷歌不同的标记不同的信息窗口中添加不同的图像地图API V2为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做很多的标记现在我想标志的每一个信息窗口必须是唯一的我已经写XML的信息窗口,但它不是相应每次工作一个单一的形象出现了。

  //设置为谷歌地图自定义信息窗口适配器
myMap.setInfoWindowAdapter(新InfoWindowAdapter(){    //使用默认信息窗口框架    公共查看getInfoWindow(标记为arg0){
        返回null;
    }    //定义信息窗口的内容    公共查看getInfoContents(标记标记){        //从布局文件info_window_layout获取视图
        视图V = getLayoutInflater()。膨胀(
                R.layout.info_window_layout,NULL);        //获取从标记的位置
        经纬度的latLng = marker.getPosition();
        双纬度= latLng.latitude;
        双langitude = latLng.longitude;        字符串经纬度=的String.format(%6F,纬度);
        字符串LNG =的String.format(%6F,langitude);        Toast.makeText(getApplicationContext(),纬度+ - + LNG,Toast.LENGTH_SHORT).show();
        //获取参照TextView的设置经度
    TextView的tvLng =(TextView中)v.findViewById(R.id.tv1);
    ImageView的图标=(ImageView的)v.findViewById(R.id.icons);    如果(lat.equals(73.057130)及与放大器; lng.equals(33.721140))
    {
        icon.setImageResource(R.drawable.hbl_icon);    }
    其他
    {        icon.setImageResource(R.drawable.alflah_icon);
    }
        //返回包含信息窗口内容的视图
        返回伏;    }});

在myMap.setInfoWindowAdapter敬酒是显示同一纬度,但信息窗口显示不显示,如果条件始终显示其他condition.everything一个图像的图像工作正常,但图像没有显示正确的好心帮。
我的XML是:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向>    < ImageView的
        机器人:ID =@ + ID /图标
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_margin =5DP/>    <的TextView
        机器人:ID =@ + ID / TV1
        机器人:文字=获取路线
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_margin =5DP/>< / LinearLayout中>


解决方案

您不应使用经纬度来确定标记 这个bug 的。

您可以使用标题/段代替,使该值IFS或有一个地图<标记,YourModel> 所有标记,并保持图标资源ID在该模式。

或者你也可以使用 Android地图扩展,这将增加像功能 Marker.setData(对象)对象Marker.getData()并保持你的模型图标资源ID接近为标记。

I have made lot of markers now I want each information window of marker must be unique I have written xml for information window but its not working accordingly every time a single image shows up.

// Setting a custom info window adapter for the google map
myMap.setInfoWindowAdapter(new InfoWindowAdapter() {

    // Use default InfoWindow frame

    public View getInfoWindow(Marker arg0) {
        return null;
    }

    // Defines the contents of the InfoWindow

    public View getInfoContents(Marker marker) {

        // Getting view from the layout file info_window_layout
        View v = getLayoutInflater().inflate(
                R.layout.info_window_layout, null);

        // Getting the position from the marker
        LatLng latLng = marker.getPosition();
        Double latitude=latLng.latitude;
        Double langitude=latLng.longitude;

        String lat = String.format("%.6f", latitude);
        String lng = String.format("%.6f", langitude);

        Toast.makeText(getApplicationContext(), lat+"----"+lng,Toast.LENGTH_SHORT).show();
        // Getting reference to the TextView to set longitude
    TextView tvLng = (TextView) v.findViewById(R.id.tv1);
    ImageView icon = (ImageView) v.findViewById(R.id.icons);

    if(lat.equals("73.057130") && lng.equals("33.721140"))
    {
        icon.setImageResource(R.drawable.hbl_icon);

    }
    else
    {

        icon.setImageResource(R.drawable.alflah_icon);
    }
        // Returning the view containing InfoWindow contents
        return v;

    }

});

in myMap.setInfoWindowAdapter the toast is showing the same latitude but the information window appearing is not showing the image in if condition and always showing a image in else condition.everything works fine but the image is not showing proper kindly help. my xml is :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/icons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

    <TextView
        android:id="@+id/tv1"
        android:text="Get Directions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

</LinearLayout>

解决方案

You should not use LatLng to identify Marker because of this bug.

You may use title / snippet instead and make ifs on that value or have a Map<Marker, YourModel> of all markers and keep icon resource id in that model.

Or you can use Android Maps Extensions, which adds functions like Marker.setData(Object) and Object Marker.getData() and keep your model with icon resource id close to marker.

这篇关于如何在谷歌不同的标记不同的信息窗口中添加不同的图像地图API V2为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆