从JSON获取坐标并在Android上的谷歌地图中移动到它们

从JSON获取坐标并在Android上的谷歌地图中移动到它们,android,json,google-maps,Android,Json,Google Maps,我对JAVA编程非常陌生,但我遇到了很大的麻烦,这取决于我的工作。无论如何 好的,我这里有一个json: { "GetPOIByTypeResult": [ { "Address": { "City": "Bucuresti", "ID": 1, "Number": 3, "Street": "Otopeni" }, "ID": 1,

我对JAVA编程非常陌生,但我遇到了很大的麻烦,这取决于我的工作。无论如何 好的,我这里有一个json:

{
"GetPOIByTypeResult": [
    {
        "Address": {
            "City": "Bucuresti",
            "ID": 1,
            "Number": 3,
            "Street": "Otopeni"
        },
        "ID": 1,
        "IsSpecial": true,
        "Latitude": 44.542869567871094,
        "Logo": "6fb43083ee663364ef6771293653e56b.jpg",
        "Longitude": 26.06893539428711,
        "Name": "Spitalul Judetean",
        "Phone": "085228291",
        "Remark": "Normal Hospital",
        "Schedule": "Monday to Friday",
        "Specialities": [
            {
                "ID": 1,
                "Name": "Stomatologie"
            },
            {
                "ID": 2,
                "Name": "Radiologie"
            },
            {
                "ID": 3,
                "Name": "Cardiologie"
            },
            {
                "ID": 4,
                "Name": "Ginecologie"
            },
            {
                "ID": 5,
                "Name": "Pediatrie"
            },
            {
                "ID": 6,
                "Name": "Patologie"
            },
            {
                "ID": 7,
                "Name": "Oncologie"
            },
            {
                "ID": 8,
                "Name": "Macelarie"
            },
            {
                "ID": 9,
                "Name": "Oftalmologie"
            },
            {
                "ID": 10,
                "Name": "Ghipsologie"
            }
        ],
        "Type": "Hospital"
    },
我需要从JSON中获取纬度和经度,并在我的应用程序中的谷歌地图上显示位置。 我这里有一个小代码片段,它可以很好地处理本地坐标,比如输入我自己的数字,但我希望它能从JSON中获取

drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
GeoPoint point2 = new GeoPoint((int)(44.55332946777344*1E6),(int)(26.07666015625*1E6));
    CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, "Bucuresti Spital 2", 
            "(Spitalul 2)", 
            "http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");       
    itemizedOverlay.addOverlay(overlayItem2);</code>
drawable=getResources().getDrawable(R.drawable.marker);
itemizedOverlay=新的自定义itemizedOverlay(可绘制,地图视图);
地质点2=新的地质点((内部)(44.55332946777344*1E6),(内部)(26.07666015625*1E6));
CustomOverlayItem overlayItem2=新CustomOverlayItem(第2点,“Bucuresti Spital 2”,
“(Spitalul 2)”,
"http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@(V1)SX40(CR0,0,40,54);;
itemizedOverlay.addOverlay(overlayItem2)
我已经设置了一个JSONparser,我只是不知道如何使mapcontroller动画化到我的坐标所在的点,所以我想在这方面得到一些帮助:-S

编辑:这就是我解决问题的方法,也许对其他人也有帮助。

drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(
            drawable, mapView); //showing marker on the map
public void showHospitalList(ArrayList<Hospitals> hospitals) {

    for (int i = 0; i < hospitals.size(); i++) {

        Hospitals hospital = hospitals.get(i);
        CustomOverlayItem temp1 = toOverlay(hospital);
        itemizedOverlay.addOverlay(temp1);
    }
    mapOverlays.add(itemizedOverlay); //this is to get the list in the activity
}

public CustomOverlayItem toOverlay(Hospitals hospitals) {

    GeoPoint point = new GeoPoint((int) (hospitals.Latitude * 1E6),
            (int) (hospitals.Longitude * 1E6));

    CustomOverlayItem temp = new CustomOverlayItem(
            point, hospitals.Name, hospitals.Phone, hospitals.Type);

    return temp;
// used the hospitals object to define the cordinates and then multiplied by 1E6 to make it compatible(from double to int)  
// Last line defines the balloon pop-up and what to show(everything is from json).
}  
drawable=getResources().getDrawable(R.drawable.marker);
itemizedOverlay=新的自定义itemizedOverlay(
可绘制,地图视图)//在地图上显示标记
公立医院列表(ArrayList医院){
对于(int i=0;i

感谢您帮助处理JSON。您可以使用一些库,如Gson或Jackson。有关更多信息: . 或者,您也可以通过使用自己解析它们


你似乎在问两个问题。1) 解析JSON以获得lat/long。2) 将动画设置到该位置。尽量不要混淆,这样你才能更好地理解。解析JSON并在对象中存储lat/long,然后在设置贴图动画时使用该对象。祝你好运:)我是Android编程新手,你能给我一个例子如何在一个对象中存储lat/long并在我上面的代码中使用它吗?如何修改这一行,使它从json中获得lat/long?这是我最大的问题。我对android编程非常陌生,请帮忙<代码>代码
地质点2=新地质点((int)(44.55332946777344*1E6),(int)(26.07666015625*1E6))<代码>代码非常感谢,我实际上是通过其他方式解决了我的问题,但主要思想是基于您的代码,因此非常感谢:)
String jsonString = ... // Your JSON
List<GeoPoint> locationList = new ArrayList<GeoPoint>();
Double lat, lng; // temp
JSONArray jsonArray = new JSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject jsonObject = jsonArray.getJSONObject(i);
    lat = jsonObject.getDouble("Latitude");
    lng = jsonObject.getDouble("Longtitude");
    locationList.add(
        new GeoPoint((int)(lat*1E6),(int)(lng*1E6)));
}
MapView mapView = (MapView) findViewById(R.id.map);

MapController mc = mapView.getController();
// Set Zoom level of this map (1-21).
mc.setZoom(21);
int x = 0; // Position to get location
GeoPoint point2 = locationList.get(x); // Get Object from list
// This call handle animation to move map to display the given location
mc.animateTo(point2);
mapView.postInvalidate();