我如何从谷歌地图JSON数组发布多个标记 [英] How do I post multiple markers from a JSON array on google maps

查看:126
本文介绍了我如何从谷歌地图JSON数组发布多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序带有一个数组从网站

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

{D:[{纬度 - 1.0东经: - 1.0,时间:下午7点14分01/18/2038\",\"most_recent\":\"1\",\"user_id\":\"4e3f2c6659f25a0f8400000b\"},{\"latitude\":-1.0,\"longitude\":-1.0,\"time\":\"07:14下午01/18/2038\",\"most_recent\":\"0\",\"user_id\":\"4e3f2c6659f25a0f8400000b\"},{\"latitude\":-1.0,\"longitude\":-1.0,\"time\":\"07:14下午01/18/2038\",\"most_recent\":\"0\",\"user_id\":\"4e3f2c6659f25a0f8400000b\"},{\"latitude\":34.0608,\"longitude\":-118.454,\"time\":\"07:14下午01/18/2038\",\"most_recent\":\"1\",\"user_id\":\"4e3da65e59f25a3956000005\"},{\"latitude\":34.0608,\"longitude\":-118.454,\"time\":\"07:14下午01/18/2038\",\"most_recent\":\"0\",\"user_id\":\"4e3da65e59f25a3956000005\"},{\"latitude\":34.0608,\"longitude\":-118.454,\"time\":\"07:14 PM 2038年1月18日,most_recent:0,USER_ID:4e3da65e59f25a3956000005}]}

{"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"}]}

你可以看到每个项目都有一个经度和纬度组成部分,也是一个id。

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

如何修改这个程序来显示一个绿色针 R.drawable.greenpin 或蓝色针 R.drawable.bluepin 为USER_ID:4e3f2c6659f25a0f8400000b或USER_ID:阵列中的4e3da65e59f25a3956000005为每一个项目(应该是三个蓝色销和在这些位置的三个绿色销)

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.

推荐答案

我不理解什么ü想,但我的情况下,对我来说这code的工作,在适当的纬度,经度地址放标志物。

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。

这篇关于我如何从谷歌地图JSON数组发布多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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