2013-01-23 3 views
0

그래서 나는 구글 장소 API를 사용하고있어 문제가있어.Google 장소 리뷰, jsonparser에 arraylist

전체 코드가 너무 크기 때문에 여기서는 전체 코드를 작성하지 않겠습니다.

public class PlacesList implements Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 

    @Key 
    public String status; 

    @Key 
    public List<Place> results; 



} 
:

여기
package com.androidhive.googleplacesandmaps; 

import java.io.Serializable; 

import com.google.api.client.util.Key; 

/** Implement this class from "Serializable" 
* So that you can pass this class Object to another using Intents 
* Otherwise you can't pass to another actitivy 
* */ 
public class Place implements Serializable { 

    @Key 
    public String id; 

    @Key 
    public String name; 

    @Key 
    public String reference; 

    @Key 
    public String icon; 

    @Key 
    public String vicinity; 

    @Key 
    public Geometry geometry; 

    @Key 
    public String formatted_address; 

    @Key 
    public String formatted_phone_number; 

    @Override 
    public String toString() { 
     return name + " - " + id + " - " + reference; 
    } 

    public static class Geometry implements Serializable 
    { 
     @Key 
     public Location location; 
    } 

    public static class Location implements Serializable 
    { 
     @Key 
     public double lat; 

     @Key 
     public double lng; 
    } 

} 

내가 결과를 얻을 방법은 다음과 같습니다

{ 
    "html_attributions" : [], 
    "result" : { 
     "address_components" : [ 
     { 
      "long_name" : "48", 
      "short_name" : "48", 
      "types" : [ "street_number" ] 
     }, 
     { 
      "long_name" : "Pirrama Road", 
      "short_name" : "Pirrama Road", 
      "types" : [ "route" ] 
     }, 
     { 
      "long_name" : "Pyrmont", 
      "short_name" : "Pyrmont", 
      "types" : [ "locality", "political" ] 
     }, 
     { 
      "long_name" : "NSW", 
      "short_name" : "NSW", 
      "types" : [ "administrative_area_level_1", "political" ] 
     }, 
     { 
      "long_name" : "AU", 
      "short_name" : "AU", 
      "types" : [ "country", "political" ] 
     }, 
     { 
      "long_name" : "2009", 
      "short_name" : "2009", 
      "types" : [ "postal_code" ] 
     } 
     ], 
     "events" : [ 
     { 
      "event_id" : "9lJ_jK1GfhX", 
      "start_time" : 1293865200, 
      "summary" : "<p>A visit from author John Doe, who will read from his latest book.</p> 
         <p>A limited number of signed copies will be available.</p>", 
      "url" : "http://www.example.com/john_doe_visit.html" 
     } 
     ], 
     "formatted_address" : "48 Pirrama Road, Pyrmont NSW, Australia", 
     "formatted_phone_number" : "(02) 9374 4000", 
     "geometry" : { 
     "location" : { 
      "lat" : -33.8669710, 
      "lng" : 151.1958750 
     } 
     }, 
     "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", 
     "id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7", 
     "international_phone_number" : "+61 2 9374 4000", 
     "name" : "Google Sydney", 
     "rating" : 4.70, 
     "reference" : "CnRsAAAA98C4wD-VFvzGq-KHVEFhlHuy1TD1W6UYZw7KjuvfVsKMRZkbCVBVDxXFOOCM108n9PuJMJxeAxix3WB6B16c1p2bY1ZQyOrcu1d9247xQhUmPgYjN37JMo5QBsWipTsnoIZA9yAzA-0pnxFM6yAcDhIQbU0z05f3xD3m9NQnhEDjvBoUw-BdcocVpXzKFcnMXUpf-nkyF1w", 
     "reviews" : [ 
     { 
      "aspects" : [ 
       { 
        "rating" : 3, 
        "type" : "quality" 
       } 
      ], 
      "author_name" : "Simon Bengtsson", 
      "author_url" : "https://plus.google.com/104675092887960962573", 
      "text" : "Just went inside to have a look at Google. Amazing.", 
      "time" : 1338440552869 
     }, 
     { 
      "aspects" : [ 
       { 
       "rating" : 3, 
       "type" : "quality" 
       } 
      ], 
      "author_name" : "Felix Rauch Valenti", 
      "author_url" : "https://plus.google.com/103291556674373289857", 
      "text" : "Best place to work :-)", 
      "time" : 1338411244325 
     }, 
     { 
      "aspects" : [ 
       { 
       "rating" : 3, 
       "type" : "quality" 
       } 
      ], 
      "author_name" : "Chris", 
      "text" : "Great place to work, always lots of free food!", 
      "time" : 1330467089039 
     } 
     ], 
     "types" : [ "establishment" ], 
     "url" : "http://maps.google.com/maps/place?cid=10281119596374313554", 
     "vicinity" : "48 Pirrama Road, Pyrmont", 
     "website" : "http://www.google.com.au/" 
    }, 
    "status" : "OK" 
} 

는 지금 모두 여기에 저장 :하지만이 내가 구글 API를 호출 할 때마다 내가 resuls 무엇을 얻을 것입니다

이제 내 질문은 :

나는 google에서 당신이 볼 수 있습니다 photo_r eference. 하지만 그것은 배열이고 첫 번째 photo_reference가 필요합니다. 내 코드에서 어떻게 얻을 수 있습니까? 당신이 사진의 API에 또 다른 요청을해야처럼이 당신에게 사진에 대한 참조를 얻을 것이다

+0

보면? 제발 좀 더 분명히 해줘 요? –

+0

photo_reference가 필요합니다. 그래서 내가하고 싶었던 것은 @Key를 넣는 것입니다. public String photo_reference; PLACE 수업에서. 하지만 그건 작동하지 않습니다 – Laurenswuyts

답변

0
JSONObject res = // your google api results 
JSONArray photos = res.getJSONArray("photo_reference"); // Extract the JSONArray 

// Get the item at index 0, which should be a reference to the first image 
String photo = photos.getString(0); 

, 그것은 보인다. 사진의 API를 사용하는 방법에 대한 자세한 내용은

https://maps.googleapis.com/maps/api/place/photo?parameters 

, 어떻게 일반적으로 JSON을 구문 분석 묻는 https://developers.google.com/places/documentation/photos

+0

하지만 다른 수업에서 결과를 얻었습니다 다시 질문을 보니 제가 편집했습니다. – Laurenswuyts

+0

photo_reference가 필요합니다. 그래서 내가하고 싶었던 것은 @Key public String photo_reference; PLACE 수업에서. 하지만 그건 효과가 없어요. – Laurenswuyts