Search code examples
androidgoogle-mapsgoogle-geocoder

Get geocode from autocomplete places


I am using this tutorial to show my user list of places, which he/she can picked after mark some letters. https://developers.google.com/places/documentation/autocomplete?hl=pl

Is there any solution to get picked place geocode? I don't want to use Google Geocoder, because it works only if user reboot his/her device.

Please for any help ;-)


Solution

  •         utf8s = location.getBytes("UTF-8");
            String place = new String(utf8s, "UTF-8");
            place = place.trim().replace(" ", "+");
    
            HttpGet request =
            new HttpGet("https://maps.googleapis.com/maps/api/geocode/json?address="+place+",+CA&key=AIzaSyAXDKR0cSN7kp4tfuUspGZt-zTW5IAa6hM");
    
            result = httpclient.execute(request, handler);
            JSONObject response = new JSONObject(result);
            JSONObject geometry = response.getJSONArray("results").getJSONObject(0).getJSONObject("geometry");
    
            JSONObject location= geometry.getJSONObject("location");