gpt4 book ai didi

android - 从 JSON 响应在 Google map 上添加多个标记

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:15:35 25 4
gpt4 key购买 nike

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);
}

我得到的经纬度:

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

我想要的是根据我的 JSON 响应在 Google map 上放置多个带有地名的标记。但是我无法放置标记。

最佳答案

为此尝试这些代码行:-

 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)));


}

关于android - 从 JSON 响应在 Google map 上添加多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36004099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com