2016-04-07 17 views
2

Ich versuche, eine Möglichkeit zu finden, Foto-Referenz-String von Google Orte API zu erhalten. Dies ist das Format von Google:Holen Sie sich Fotoreferenz

"photos" : [ 
      { 
       "height" : 768, 
       "html_attributions" : [ 
        "\u003ca href=\"https://maps.google.com/maps/contrib/114756359878708427597/photos\"\u003eHotel Olympic\u003c/a\u003e" 
       ], 
       "photo_reference" : "CmRdAAAAGWSabKG9f1wwRa1-dg0RVlb_m54RQDO023QTxEgOdFvlE2KjnK9Saxiqnxanr0yTCdbEg183RUk0kncFVwmFoQ8kn5yjnPHGZ-3-vi8Jck-6MbfJLU__h7hibPJ4tko3EhAhSR1B_4-eT4c6A_s_32I_GhTFiO19eMhOD5x5xYfB4DN3ABOtKA", 
       "width" : 1024 
      } 
     ] 

Wie kann ich die Foto Referenz Zeichenfolge? Gibt es eine Möglichkeit, genau das zu erreichen, oder muss ich etwas anderes tun?

Das ist mein Java-Code:

private HashMap<String, String> getPlace(JSONObject jPlace){ 
    HashMap<String, String> place = new HashMap<String, String>(); 
    String photo_reference= "-NA-"; 
     if(!jPlace.isNull("photos")){ 
      //something to do here 
     } 
     //a string builder here to create the url 
     place.put("photo", theUrl); 
} 

wo jPlace ein Ort von Google ist platziert api in JSONObject Format

ofcource es mehr Code ist, aber ich hochgeladen nur den Teil, wo ich die JSONObject bekommen

+0

Sie müssen nur diese JSON-Zeichenfolge analysieren, da Sie die photo_reference-Zeichenfolge erhalten. –

Antwort

2

das ist, was ich in //do somethign here Teil zu tun hatte:

 StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/photo?maxwidth=50&photoreference="); 

     JSONArray photos = jPlace.getJSONArray("photos"); 

     //Run for loop for getting photo_reference string in each object 

     for (int i=0; i <= photos.length; i++){ 
      JSONObject getPhtotos = photos.getJSONObject(i); 
      String photo_reference = getPhtotos.getString("photo_reference"); 
      sb.append(photo_reference); 
      sb.append("&key=..."); 
     }