通过JSON响应在Google Map上添加多个标记 [英] Add multiple markers on Google Map from JSON response

查看:143
本文介绍了通过JSON响应在Google Map上添加多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Json的回复:

{"status":true,"message":"Successfully Alert Message","Data":[{"longitude":"70.7652417","latitude":"22.2889975","alert_message":"abcd"},{"longitude":"70.7652417","latitude":"22.2888975","alert_message":"pqr",},{longitude":"70.7662417","latitude":"22.2898975","alert_message":"xyz"}]}

我做了什么:

arraylist = parseContent.getUsers(response);
adapter = new ListViewAdapter(getApplicationContext(), arraylist);
Log.d("typelist", arraylist.toString());
lv.setAdapter(adapter);

for (int i =0;i<arraylist.size();i++)
{
    longitude1 = arraylist.get(i).get("longitude");
    latitude1 = arraylist.get(i).get("latitude");

    // MarkerOptions mp = new MarkerOptions();

    Double long1= Double.parseDouble(longitude1);
    Double lat1= Double.parseDouble(latitude1);

    /* mp.position(new LatLng(long1,lat1));
    mp.title("my position");
    googleMap.addMarker(mp);*/
    /*  Marker marker =  googleMap.addMarker(new MarkerOptions()
        .position(new LatLng(long1, lat1))
        .title("Hello world")
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.flag)));*/
    // marker.add(marker);
    // arraylist.add(marker);
    // googleMap.addMarker(marker);

    googleMap.addMarker(new MarkerOptions().position(new LatLng(long1, lat1)));
    Log.e("PlaceLL",lat1+" "+long1);
}

我正在得到的纬度和经度

Latitude and longitude I am getting:

LL: 22.2889975 70.7652417
LL: 22.2888975 70.7652417
LL: 22.2898975 70.7662417

我想要从我的JSON响应中在Google Map上放置多个带有地名的标记.但是我无法放置标记.

What I want is to put multiple markers with place name on Google Map, from my JSON response. But I am not able to place markers.

推荐答案

尝试以下代码行:-

 private Marker locationMarker;

 for (int i = 0; i < arraylist.size(); i++) 
 {
   if(i==0) ////FOR ANIMATING THE CAMERA FOCUS FIRST TIME ON THE GOOGLE MAP
   {
    CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(Double.parseDouble(arraylist.get(i).getLatitute()), Double.parseDouble(arraylist.get(i).getLongitute()))).zoom(15).build();
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
   }

   locationMarker = googleMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(arraylist.get(i).getLatitute()), Double.parseDouble(arraylist.get(i).getLongitute()))).icon(BitmapDescriptorFactory.fromResource(R.drawable.YOUR_DRAWABLE)));


  }

这篇关于通过JSON响应在Google Map上添加多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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