How do I post multiple markers from a JSON array on google maps

拟墨画扇 提交于 2019-12-11 19:37:25

问题


I have an android app that takes an array from a website

{"d":[{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"1","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":-1.0,"longitude":-1.0,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3f2c6659f25a0f8400000b"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"1","user_id":"4e3da65e59f25a3956000005"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3da65e59f25a3956000005"},{"latitude":34.0608,"longitude":-118.454,"time":"07:14 PM 01/18/2038","most_recent":"0","user_id":"4e3da65e59f25a3956000005"}]}

as you can see each item has a latitude and longitude component as well as an id.

How do I modify this program to show either a green pin R.drawable.greenpin or a blue pin R.drawable.bluepin for "user_id":"4e3f2c6659f25a0f8400000b" or "user_id":"4e3da65e59f25a3956000005" for each of the items in the array ( should be three blue pins and three green pins at these locations)

public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
{ 
super.draw(canvas,mapView,shadow);
Point screenPts=new Point();
mapView.getProjection().toPixels(p,screenPts);
Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.greenpin);
canvas.drawBitmap(bmp,screenPts.x,screenPts.y-50,null);
return true;
}
}

//to add the location marker
MapOverlay mapOverlay=new MapOverlay();
List<Overlay> listOfOVerlays=mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);

The method that I have confuses me a bit because it draws the point based on the screen point. I would rather add these points by inserting the pins by the longitude and latitude of the arrays.


回答1:


I don't understanding what u want but in my case this code work for me, for put marker in appropriate lat,long address.

    myPoint = new GeoPoint(((int) LATITUDE_Add) * 1E6),(int)LONGITUDE_Add) * 1E6));
drawable = getResources().getDrawable(R.drawable.marker_blue);
itemizedoverlay = new MapOverLay(drawable, MapPage.this, mapview);
OverlayItem overlayitem = new OverlayItem(myPoint, address, "");

 itemizedoverlay.addOverlay(overlayitem);
 mapOverlays.add(itemizedoverlay);
 mapview.getController().animateTo(myPoint);

Thnx.



来源:https://stackoverflow.com/questions/7171012/how-do-i-post-multiple-markers-from-a-json-array-on-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!