Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 添加到谷歌地图,然后在上面搜索_Android_Google Maps_Google Maps Api 3 - Fatal编程技术网

Android 添加到谷歌地图,然后在上面搜索

Android 添加到谷歌地图,然后在上面搜索,android,google-maps,google-maps-api-3,Android,Google Maps,Google Maps Api 3,我是谷歌地图和谷歌地图api的新手 我想知道我的android应用程序是如何将数据添加到谷歌地图的,比如位置 然后其他用户可以根据最近的搜索请求获取此位置 换句话说 我的应用程序将允许人们将他们的位置添加到我的谷歌地图,并允许用户按位置搜索到其他用户添加的最近位置,而不仅仅是谷歌位置库 因此,应用程序可以获取包含用户位置周围最近位置的json文件 我如何使用谷歌API做到这一点?可能会有所帮助 // Fetches all places from GooglePlaces AutoComplet

我是谷歌地图和谷歌地图api的新手 我想知道我的android应用程序是如何将数据添加到谷歌地图的,比如位置 然后其他用户可以根据最近的搜索请求获取此位置 换句话说

我的应用程序将允许人们将他们的位置添加到我的谷歌地图,并允许用户按位置搜索到其他用户添加的最近位置,而不仅仅是谷歌位置库 因此,应用程序可以获取包含用户位置周围最近位置的json文件

我如何使用谷歌API做到这一点?

可能会有所帮助

// Fetches all places from GooglePlaces AutoComplete Web Service
private class PlacesTask extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... place) {
        // For storing data from web service
        String data = "";

        // Obtain browser key from https://code.google.com/apis/console
        String key = "key=key";

        String input="";

        try {
            input = "input=" + URLEncoder.encode(place[0], "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }       


        // place type to be searched
        String types = "types=geocode";

        // Sensor enabled
        String sensor = "sensor=false";         

        // Building the parameters to the web service
        String parameters = input+"&"+types+"&"+sensor+"&"+key;

        // Output format
        String output = "json";

        // Building the url to the web service
        String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;

        try{
            // Fetching the data from web service in background
            data = downloadUrl(url);
        }catch(Exception e){
            Log.d("Background Task",e.toString());
        }
        return data;        
    }

    @Override
    protected void onPostExecute(String result) {           
        super.onPostExecute(result);

        // Creating ParserTask
        parserTask = new ParserTask();

        // Starting Parsing the JSON string returned by Web Service
        parserTask.execute(result);
    }       
}


/** A class to parse the Google Places in JSON format */
private class ParserTask extends AsyncTask<String, Integer, List<HashMap<String,String>>>{

    JSONObject jObject;

    @Override
    protected List<HashMap<String, String>> doInBackground(String... jsonData) {            

        List<HashMap<String, String>> places = null;

        PlaceJSONParser placeJsonParser = new PlaceJSONParser();

        try{
            jObject = new JSONObject(jsonData[0]);

            // Getting the parsed data as a List construct
            places = placeJsonParser.parse(jObject);

        }catch(Exception e){
            Log.d("Exception",e.toString());
        }
        return places;
    }

    @Override
    protected void onPostExecute(List<HashMap<String, String>> result) {            

            String[] from = new String[] { "description"};
            int[] to = new int[] { android.R.id.text1 };

            // Creating a SimpleAdapter for the AutoCompleteTextView            
            SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), result, android.R.layout.simple_list_item_1, from, to);             

            // Setting the adapter
            atvPlaces.setAdapter(adapter);
    }           
}    
输出


如果你想在应用程序中显示谷歌地图视图,你需要使用谷歌API。我不想从谷歌地图中获取最近的位置列表,并在我的应用程序中使用它。这很好:但我需要保存我的应用程序用户位置,然后检索特定地址用户位置周围的最近位置列表