【问题标题】:android: get a place "about" information from google placesandroid:从谷歌地方获取一个地方“关于”的信息
【发布时间】:2023-03-22 19:53:01
【问题描述】:

我正在使用 Google 地图构建 Android 应用。 有没有办法从 Google Places API 检索地点信息? 我的意思是用几行描述该地点的纯文本(不是地址、评级、id 等的常规属性)。只是“关于”这个地方。

谢谢。

【问题讨论】:

    标签: android google-places-api


    【解决方案1】:

    您需要 GooglePlaces API 密钥,这是我的代码。

    public class GooglePlacesDataSource {
    
    private static final String URL = "https://maps.googleapis.com/maps/api/place/search/json?";
    private static final String TYPES = "accounting|airport|amusement_park|aquarium|art_gallery|atm|bakery|bank|bar|beauty_salon|bicycle_store|book_store|bowling_alley|bus_station|cafe|campground|car_dealer|car_rental|car_repair|car_wash|casino|cemetery|church|city_hall|clothing_store|convenience_store|courthouse|dentist|department_store|doctor|electrician|electronics_store|embassy|establishment|finance|fire_station|florist|food|funeral_home|furniture_store|gas_station|general_contractor|grocery_or_supermarket|gym|hair_care|hardware_store|health|hindu_temple|home_goods_store|hospital|insurance_agency|jewelry_store|laundry|lawyer|library|liquor_store|local_government_office|locksmith|lodging|meal_delivery|meal_takeaway|mosque|movie_rental|movie_theater|moving_company|museum|night_club|painter|park|parking|pet_store|pharmacy|physiotherapist|place_of_worship|plumber|police|post_office|real_estate_agency|restaurant|roofing_contractor|rv_park|school|shoe_store|shopping_mall|spa|stadium|storage|store|subway_station|synagogue|taxi_stand|train_station|travel_agency|university|veterinary_care|zoo"; //all places
    
    private static String key = null;
    
    public GooglePlacesDataSource(Resources res) {
        if (res == null) throw new NullPointerException();
    
        key = res.getString(R.string.google_places_api_key); //add string with your's google places api key
    }
    
    @Override
    public String createRequestURL(double lat, double lon, double alt, float radius, String locale) {
        try {
            return URL + "location="+lat+","+lon+"&radius="+(radius*1000.0f)+"&types="+TYPES+"&sensor=true&key="+key;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    /**
     Parse URL and return List of Object
     */
    
    @Override
    public List<Object> parse(String URL) {
        if (URL == null) throw new NullPointerException();
    
        InputStream stream = null;
        stream = getHttpGETInputStream(URL);
        if (stream == null) throw new NullPointerException();
    
        String string = null;
        string = getHttpInputString(stream);
        if (string == null) throw new NullPointerException();
    
        JSONObject json = null;
        try {
            json = new JSONObject(string);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (json == null) throw new NullPointerException();
    
        return parse(json);
    }}
    

    【讨论】:

    • 抱歉,您没有理解我的问题。我只想要几行描述这个地方......所以我可以把它呈现给用户......
    • 当你解析 json 对象时,你可以取一行描述地点,如名称和描述
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多