在MySQL中使用自定义INFOWINDOW [英] Use Custom INFOWINDOW with MySQL

查看:126
本文介绍了在MySQL中使用自定义INFOWINDOW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,其中显示存储在数据库(MySQL)中的标记,每个标记具有不同的字段(例如:名称,电子邮件,地址等),因为"MarkerOptions"仅允许我使用".tittle,".snippet我要附加的某些字段已被删除,我现在知道我必须使用自定义信息窗口来显示我想要的所有字段.我怎样才能做到这一点? 我的代码:

I have a map where i display markers that are stored in a db (MySQL),each marker have different fields with it (for example: name, email, addres, etc), since "MarkerOptions" only let me use ".tittle",".snippet"some of the fields that i want to attach are left out, i know now that i have to use a custom infowindow to show all the fields that i want to. How can i do this? My code:

主要:

ArrayList<HashMap<String, String>> location = null;
    String url = "http://appserver.eco.mx/movil/getLanLong.php";
    try {

        JSONArray data = new JSONArray(getHttpGet(url));
        location = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map;

        for(int i = 0; i < data.length(); i++){
            JSONObject c = data.getJSONObject(i);
            map = new HashMap<String, String>();
            map.put("id", c.getString("id"));
            map.put("campo_latitud", c.getString("campo_latitud"));
            map.put("campo_longitud", c.getString("campo_longitud"));
            map.put("campo_categoria", c.getString("campo_categoria"));
            map.put("campo_estado", c.getString("campo_estado"));
            location.add(map);
        }
    } catch (JSONException e) {
// TODO Auto-generated catch block
        e.printStackTrace();
    }

    String campouno = "";
    if(!TextUtils.isEmpty(campouno)){
        double campo_latitud = Double.parseDouble(campouno);
    }
    //campo_latitud = Double.parseDouble(location.get(0).get("Latitude").toString());
    String campodos = "";
    if(!TextUtils.isEmpty(campodos)){
        double campo_longitud = Double.parseDouble(campodos);
    }

    for (int i = 0; i < location.size(); i++) {
        if(!TextUtils.isEmpty(location.get(i).get("campo_latitud").toString())&&!TextUtils.isEmpty(location.get(i).get("campo_longitud").toString())) {
            campo_latitud = Double.parseDouble(location.get(i).get("campo_latitud").toString());
            campo_longitud = Double.parseDouble(location.get(i).get("campo_longitud").toString());
        } 

String name = location.get(i).get("campo_categoria").toString();
        //String des = location.get(i).get("campo_descripcion").toString();

        if(location.get(i).get("campo_categoria").toString().equals("Obras publicas")){
            //System.out.println(location.get(i).get("campo_descripcion").toString());
            googleMap.addMarker(new MarkerOptions().position(new LatLng(campo_latitud, campo_longitud)).title(name).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_op)));
        }
  }}

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">

<TextView
    android:id="@+id/info_window_nombre"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:paddingLeft="5dp"
    android:text="Carlo Estrada Solano" />

<TextView
    android:id="@+id/info_window_placas"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="20sp"
    android:layout_below="@id/info_window_nombre"
    android:paddingLeft="5dp"
    android:text="Placas: SX5487" />

<TextView
    android:id="@+id/info_window_estado"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/info_window_placas"
    android:paddingLeft="5dp"
    android:text="Estado: Activo" />

</LinearLayout>

InfoWindow类:

InfoWindow class:

public class AdaptadorInforWindow implements GoogleMap.InfoWindowAdapter {

private static final String TAG = "CustomInfoWindowAdapter";
private LayoutInflater inflater;

public AdaptadorInforWindow(LayoutInflater inflater){
    this.inflater = inflater;
}

@Override
public View getInfoWindow(Marker marker) {
    //Carga layout personalizado.
    View v = inflater.inflate(R.layout.infowindow_layout, null);
    String[] info = marker.getTitle().split("&");
    String url = marker.getSnippet();
    ((TextView)v.findViewById(R.id.info_window_nombre)).setText("Lina Cortés");
    ((TextView)v.findViewById(R.id.info_window_placas)).setText("Placas: SRX32");
    ((TextView)v.findViewById(R.id.info_window_estado)).setText("Estado: Activo");

    return v;
}

@Override
public View getInfoContents(Marker marker) {
    return null;
    }
}

设置googlemap:

set googlemap:

myGoogleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(getActivity())));

推荐答案

使用标记键将标记存储在Hashmap中.然后使用使用hashmap对象的自定义信息窗口"检索其他信息. 当您单击标记时,它将显示相关信息.

Store markers in Hashmap by Using the marker key. Then use the Custom infowindow using hashmap object to retrieve the others information. When you will click marker it will show the related information.

或者您可以从8:00开始在病房观看此视频. 单击此处

or you can watch this video from 8:00 on wards. Click Here

这篇关于在MySQL中使用自定义INFOWINDOW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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