Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在json解析中使用if/else在地图上显示标记_Json_Google Maps_If Statement_Google Maps Markers - Fatal编程技术网

在json解析中使用if/else在地图上显示标记

在json解析中使用if/else在地图上显示标记,json,google-maps,if-statement,google-maps-markers,Json,Google Maps,If Statement,Google Maps Markers,我有两个json文件,第一个用于分类,第二个用于生成标记并将它们放在地图中 我的应用程序的第一个屏幕显示listview上的类别,当我单击其中一个类别时,它应该根据地图上选择的类别显示标记,我显示地图或读取json没有问题 json类别示例: { "categories": [ { "id": "01", "categoria": "Restaurante" } ] } 示例json位置: { "places": [ {

我有两个json文件,第一个用于分类,第二个用于生成标记并将它们放在地图中

我的应用程序的第一个屏幕显示listview上的类别,当我单击其中一个类别时,它应该根据地图上选择的类别显示标记,我显示地图或读取json没有问题

json类别示例:

{
  "categories": [
    {
      "id": "01",
      "categoria": "Restaurante"
    }
  ]
}
示例json位置:

{
  "places": [
    {
      "id": "01",
      "lat": "20.583566571214778",
      "long": "-100.37047419121245",
      "dist": "100m",
      "star": "1",
      "icon": "03",
      "name": "Restaurante San Pedro",
      "cat": "Restaurante",
      "sched": "9:00 - 23:00",
      "text": "Una gran seleccion de platillos para su deleite."
    }
  ]
}
问题是,它不会显示标记,我使用if来比较所选类别是否与places json中的任何类别业务相同,如果相同,则显示标记,我使用toast来查看结果并 这是一样的,我不知道为什么它不会执行if语句而不是else

if (cat == recuperamos_variable_cat) {
  LatLng lugares = new LatLng(dlatitud, dlongitud);
  Marker ubicacion2 = mapa.addMarker(new MarkerOptions().position(lugares).title(name).snippet(text));
  Toast mensaje2 = Toast.makeText(getApplicationContext(), cat + recuperamos_variable_cat, Toast.LENGTH_SHORT);
  mensaje2.show();
} else {
  Toast mensaje2 = Toast.makeText(getApplicationContext(), "No hay coincidencias", Toast.LENGTH_SHORT);
  mensaje2.show();
}
我把剩下的代码放在下面:

//recover the value of the category selected
final String recuperamos_variable_id = getIntent().getStringExtra("TAG_ID");
final String recuperamos_variable_cat = getIntent().getStringExtra("TAG_CAT");
// Hashmap for ListView
ArrayList<HashMap<String, String>> placesList = new ArrayList<HashMap<String, String>> ();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
  // Getting Array of Contacts
  places = json.getJSONArray(TAG_PLACES);
  // looping through All Contacts
  for (int i = 0; i < places.length(); i++) {
    JSONObject c = places.getJSONObject(i);
    // Storing each json item in variable
    String id = c.getString(TAG_ID);
    String lat = c.getString(TAG_LAT);
    String lon = c.getString(TAG_LONG);
    String dist = c.getString(TAG_DIST);
    String star = c.getString(TAG_STAR);
    String name = c.getString(TAG_NAME);
    String cat = c.getString(TAG_CAT);
    String icon = c.getString(TAG_ICON);
    String sched = c.getString(TAG_SCHED);
    String text = c.getString(TAG_TEXT);
    double dlatitud = Double.parseDouble(lat); //Convertimos valores a double
    double dlongitud = Double.parseDouble(lon);
    if (cat == recuperamos_variable_cat) {
      LatLng lugares = new LatLng(dlatitud, dlongitud);
      Marker ubicacion2 = mapa.addMarker(new MarkerOptions().position(lugares).title(name).snippet(text));
      Toast mensaje2 = Toast.makeText(getApplicationContext(), cat + recuperamos_variable_cat, Toast.LENGTH_SHORT);
      mensaje2.show();
    } else {
      Toast mensaje2 = Toast.makeText(getApplicationContext(), "No hay coincidencias", Toast.LENGTH_SHORT);
      mensaje2.show();
    }
  }
} catch (JSONException e) {
  e.printStackTrace();
}
//恢复所选类别的值
最终字符串recurperamos_变量_id=getIntent().getStringExtra(“TAG_id”);
最终字符串recurperamos_变量_cat=getIntent().getStringExtra(“TAG_cat”);
//ListView的Hashmap
ArrayList placesList=新的ArrayList();
//创建JSON解析器实例
JSONParser jParser=新的JSONParser();
//从URL获取JSON字符串
JSONObject json=jParser.getJSONFromUrl(url);
试一试{
//获取联系人数组
places=json.getJSONArray(标记位置);
//通过所有触点循环
对于(int i=0;i
Alredy可以做到这一点

我必须用这个

如果(cat.equals(Recurperamos_variable_cat)){

而不是

如果(cat==recurperamos_变量_cat){


希望这对将来的人有所帮助

您将两个字符串与==进行比较,这只会告诉您两个字符串变量是否指向同一个对象。要比较字符串的内容,请使用equals方法-cat.equals(Reciperamos_variable_cat)