सेवा उपलब्ध नहीं geoCoder.getFromLocation बुला जबकि ()

वोट
26

मैं कभी कभी पता गूगल बैक-एंड सेवा उपलब्ध नहीं हो सकता है।

इसलिए एक समाधान पाश करने के लिए हो सकता है जब तक मैं डेटा मिलता है।

private class getLocationDetails extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {

        Log.d(looping,  + count + );
        count++;
        double lat = Double.parseDouble(params[0]);
        double lng = Double.parseDouble(params[1]);
        List<Address> addresses = null;
        try {

            Geocoder gCoder = new Geocoder(ImageAndLocationActivity.this,
                    Locale.getDefault());
            addresses = gCoder.getFromLocation(lat, lng, 1);
            Address addr = addresses.get(0);
            user_country = addr.getCountryName();
            user_city = addr.getLocality();
            user_district = addr.getSubAdminArea();

            if (user_city == null) {

                user_city = user_district;
            }
        } catch (Exception e) {

            Log.e(Exception in getLocationDetails - , e.getMessage());
            return null;
        }

        return ;
    }

    @Override
    protected void onPostExecute(String result) {

        if (result != null) {

            Log.d(user_city = ,  + user_city);
        } else {

            new getLocationDetails().execute(CurrentLat + , CurrentLng
                    + );
        }
    }

    @Override
    protected void onPreExecute() {

    }

    @Override
    protected void onProgressUpdate(Void... values) {

    }
}

लेकिन मैं सब पर स्थान प्राप्त करने में सक्षम नहीं कर रहा हूँ:

LogCat:

02-27 16:29:49.568: D/looping(10966): 110355
02-27 16:29:49.568: E/Exception in getLocationDetails -(10966): Service not Available
02-27 16:29:49.573: D/looping(10966): 110356
02-27 16:29:49.573: E/Exception in getLocationDetails -(10966): Service not Available
02-27 16:29:49.573: D/looping(10966): 110357
02-27 16:29:49.573: E/Exception in getLocationDetails -(10966): Service not Available

और बिल्कुल मैं सभी आवश्यक अनुमतियों को शामिल किया है:

<uses-permission android:name=android.permission.INTERNET />

मैं यह कोशिश कर रहा हूँ Samsung Galaxy Note GT-N7000 (4.0.4 संस्करण)

मैं किसी भी सेटिंग याद आ रही है? उपकरण या एप्लिकेशन से संबंधित? या फिर यह आम तौर पर होता है? यदि ऐसा है तो किसी भी बेहतर समाधान इस को हल करने ??

धन्यवाद

27/02/2013 को 12:08
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


15 जवाब

वोट
4

एपीआई एक "सेवा नहीं उपलब्ध अपवाद" फेंक होगा अगर इस तरह के सेवा उपकरण पर उपलब्ध नहीं है। विधि का उपयोग करें isPresent()सेवा के होने की जाँच करने के लिए।

यह भी देखें: http://developer.android.com/reference/android/location/Geocoder.html

27/02/2013 को 12:13
का स्रोत उपयोगकर्ता

वोट
58

वास्तविक कारण है कि Geocoderकाम नहीं कर रहा था क्योंकि है NetworkLocatorकार्रवाई में मारे गए। शायद कम स्मृति के कारण या शायद आप सभी सेवाओं को मारने के लिए कार्य प्रबंधक का इस्तेमाल किया?

मुझे यकीन है कि नहीं कर रहा हूँ, लेकिन यह एक अनुमान है। मैंने पहले इस देखा है। पिछले साल मैं NetworkLocator.apk लोड और करने के लिए बाध्य करने के लिए एक पुनः कनेक्ट तंत्र लिखा था GeocoderService। मैं तो यह समस्या बनी रहती इस परिवर्तन JellyBean में विलय नहीं किया गया है लगता है।

यह केवल रिबूट द्वारा हल किया जा सकता है। (दॅ NetworkLocationServiceबूट पर लोड किया जाता है)

संपादित करें: आप नहीं देख सकेंगे JBP या केके में इस समस्या, इस सेवा के playstore एप्लिकेशन में ले जाया जाता।

27/02/2013 को 13:33
का स्रोत उपयोगकर्ता

वोट
1

इस चाल का उपयोग करें।

बस project.properties संपादित

# Project target
target=Google Inc.:Google APIs:16

कारण यह है कि जियोकोडर वर्ग कोर एंड्रॉयड ढांचे में मौजूद है, लेकिन कोड को Google API के योगदान ठीक ढंग से काम पर निर्भर करता है। यहां तक ​​कि अगर आपके AVD Google API का भी शामिल है, अपनी परियोजना अभी भी है कि विशिष्ट निर्माण लक्ष्य के खिलाफ बनाया जाना चाहिए।

11/03/2013 को 15:08
का स्रोत उपयोगकर्ता

वोट
21

वैकल्पिक हल गूगल मैप्स के लिए सीधी पहुँच का उपयोग करते हुए:

    public static LatLng getLocationFromString(String address)
        throws JSONException {

    HttpGet httpGet = new HttpGet(
            "http://maps.google.com/maps/api/geocode/json?address="
                    + URLEncoder.encode(address, "UTF-8") + "&ka&sensor=false");
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    try {
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        int b;
        while ((b = stream.read()) != -1) {
            stringBuilder.append((char) b);
        }
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

    JSONObject jsonObject = new JSONObject(stringBuilder.toString());

    double lng = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
            .getJSONObject("geometry").getJSONObject("location")
            .getDouble("lng");

    double lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
            .getJSONObject("geometry").getJSONObject("location")
            .getDouble("lat");

    return new LatLng(lat, lng);
}

    public static List<Address> getStringFromLocation(double lat, double lng)
        throws ClientProtocolException, IOException, JSONException {

    String address = String
            .format(Locale.ENGLISH,                                 "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=true&language="
                            + Locale.getDefault().getCountry(), lat, lng);
    HttpGet httpGet = new HttpGet(address);
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    List<Address> retList = null;

    response = client.execute(httpGet);
    HttpEntity entity = response.getEntity();
    InputStream stream = entity.getContent();
    int b;
    while ((b = stream.read()) != -1) {
        stringBuilder.append((char) b);
    }

    JSONObject jsonObject = new JSONObject(stringBuilder.toString());

    retList = new ArrayList<Address>();

    if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {
        JSONArray results = jsonObject.getJSONArray("results");
        for (int i = 0; i < results.length(); i++) {
            JSONObject result = results.getJSONObject(i);
            String indiStr = result.getString("formatted_address");
            Address addr = new Address(Locale.getDefault());
            addr.setAddressLine(0, indiStr);
            retList.add(addr);
        }
    }

    return retList;
}
15/07/2013 को 12:48
का स्रोत उपयोगकर्ता

वोट
0

मैं एक ही जियोकोडर त्रुटि लेकिन ऊपर लागू न था। यह मेरी Android उपकरणों में से एक को चलाने के नहीं होता। तब मैं याद आया कि मैं accedently कुछ चल रहा है सेवा को मार डाला था। समाधान कुछ सेकंड के लिए बैटरी को दूर करने के लिए और इसे फिर से स्थापित किया गया था। और यह कोड को बदले बिना :) काम किया)

18/07/2013 को 13:34
का स्रोत उपयोगकर्ता

वोट
0

कुछ उपकरणों जियोकोडर के लिए suport की जरूरत नहीं है, तो आप क्या करने की जरूरत अपने स्वयं के जियोकोडर पैदा करते हैं।

मूल रूप से आप पते के लिए गूगल का अनुरोध और json प्रतिक्रिया के इलाज के लिए एक async कार्य बनाने की जरूरत है।

aquery का उपयोग करना, मैं कुछ इस तरह करते हैं:

public void asyncJson(String address){
        address = address.replace(" ", "+");

        String url = "http://maps.googleapis.com/maps/api/geocode/json?address="+ address +"&sensor=true";

        aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {

                @Override
                public void callback(String url, JSONObject json, AjaxStatus status) {                        

                        if(json != null){

                                 //here you work with the response json
                                 JSONArray results = json.getJSONArray("results");                               
                                Toast.makeText(context, results.getJSONObject(1).getString("formatted_address"));

                        }else{                                
                                //ajax error, show error code
                                Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
                        }
                }
        });        
}
27/11/2013 को 16:34
का स्रोत उपयोगकर्ता

वोट
-1

मैं एक ही त्रुटि थी, इसे हल करने के लिए अनुमति नीचे जोड़ें।

<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
<uses-permission android:name="android.permission.INTERNET" />
19/08/2014 को 09:43
का स्रोत उपयोगकर्ता

वोट
2

इस समस्या के लिए सबसे अच्छा ठीक गूगल जियोकोडर वर्ग की तरह ही उपयोग करने के लिए करता है, तो मूल जियोकोडर असफल है

List<Address> addresses = null;    
Geocoder geocoder = new Geocoder(this);
addresses = geocoder.getFromLocation(...);
if (addresses == null || addresses.isEmpty())
addresses = MyGeocoder.getFromLocation(...);


import android.location.Address;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.AllClientPNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class MyGeocoder {

    public static List<Address> getFromLocation(double lat, double lng, int maxResult) {

        String address = String.format(Locale.ENGLISH, "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=false&language=" + Locale.getDefault().getCountry(), lat, lng);
        HttpGet httpGet = new HttpGet(address);
        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(AllClientPNames.USER_AGENT, "Mozilla/5.0 (Java) Gecko/20081007 java-geocoder");
        client.getParams().setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 5 * 1000);
        client.getParams().setIntParameter(AllClientPNames.SO_TIMEOUT, 25 * 1000);
        HttpResponse response;

        List<Address> retList = null;

        try {
            response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();
            String json = EntityUtils.toString(entity, "UTF-8");

            JSONObject jsonObject = new JSONObject(json);

            retList = new ArrayList<Address>();

            if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {
                JSONArray results = jsonObject.getJSONArray("results");
                if (results.length() > 0) {
                    for (int i = 0; i < results.length() && i < maxResult; i++) {
                        JSONObject result = results.getJSONObject(i);
                        //Log.e(MyGeocoder.class.getName(), result.toString());
                        Address addr = new Address(Locale.getDefault());
                        // addr.setAddressLine(0, result.getString("formatted_address"));

                        JSONArray components = result.getJSONArray("address_components");
                        String streetNumber = "";
                        String route = "";
                        for (int a = 0; a < components.length(); a++) {
                            JSONObject component = components.getJSONObject(a);
                            JSONArray types = component.getJSONArray("types");
                            for (int j = 0; j < types.length(); j++) {
                                String type = types.getString(j);
                                if (type.equals("locality")) {
                                    addr.setLocality(component.getString("long_name"));
                                } else if (type.equals("street_number")) {
                                    streetNumber = component.getString("long_name");
                                } else if (type.equals("route")) {
                                    route = component.getString("long_name");
                                }
                            }
                        }
                        addr.setAddressLine(0, route + " " + streetNumber);

                        addr.setLatitude(result.getJSONObject("geometry").getJSONObject("location").getDouble("lat"));
                        addr.setLongitude(result.getJSONObject("geometry").getJSONObject("location").getDouble("lng"));
                        retList.add(addr);
                    }
                }
            }


        } catch (ClientProtocolException e) {
            Log.e(MyGeocoder.class.getName(), "Error calling Google geocode webservice.", e);
        } catch (IOException e) {
            Log.e(MyGeocoder.class.getName(), "Error calling Google geocode webservice.", e);
        } catch (JSONException e) {
            Log.e(MyGeocoder.class.getName(), "Error parsing Google geocode webservice response.", e);
        }

        return retList;
    }
}
31/10/2014 को 08:24
का स्रोत उपयोगकर्ता

वोट
4

उपकरण को पुनः प्रारंभ और यह मुद्दा ठीक कर देंगे।

26/11/2014 को 09:22
का स्रोत उपयोगकर्ता

वोट
1

सेवा नहीं उपलब्ध - जियोकोडर एंड्रॉयड मैं इस पुस्तकालय मैं आशा उपयोगी हो सकता है लिखा था जब मैं कुछ पकाया रोम में इस त्रुटि मिलती है। https://github.com/dnocode/gapis

15/03/2015 को 15:45
का स्रोत उपयोगकर्ता

वोट
1

मैं कोड है कि (गूगल मैप्स के लिए सीधी पहुँच) जियोकोडर कोड के साथ "विलय कर दिया", जिन्हें आप नीचे ऊपर है उपयोग कर रहा हूँ ( "पकड़ने की कोशिश" पर विशेष ध्यान दें):

...
//address is String
if (address != null) {
    new GeocoderTask().execute(address);
}
...

// An AsyncTask class for accessing the GeoCoding Web Service
private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {

    private LatLng latLng;
    private MarkerOptions markerOptions;

    @Override
    protected List<Address> doInBackground(String... locationName) {
        // Creating an instance of Geocoder class
        Geocoder geocoder = new Geocoder(getBaseContext());
        List<Address> addresses = null;

        try {
            // Getting a maximum of 3 Address that matches the input text
            addresses = geocoder.getFromLocationName(locationName[0], 3);
        } catch (IOException e) {
            e.printStackTrace();
            try {
                addresses = getLocationFromString(locationName[0]);
            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            } catch (JSONException e1) {
                e1.printStackTrace();
            }

        }
        return addresses;
    }

    @Override
    protected void onPostExecute(List<Address> addresses) {

        if (addresses == null || addresses.size() == 0) {
            Toast.makeText(getBaseContext(), "No Location found",
                    Toast.LENGTH_SHORT).show();
            return;
        }

        // Clears all the existing markers on the map
        googleMap.clear();

        // Adding Markers on Google Map for each matching address
        for (int i = 0; i < addresses.size(); i++) {

            Address address = (Address) addresses.get(i);

            // Creating an instance of GeoPoint, to display in Google Map
            latLng = new LatLng(address.getLatitude(),
                    address.getLongitude());

            String addressText = String.format(
                    "%s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address
                            .getAddressLine(0) : "", address
                            .getCountryName());

            markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title(addressText);

            googleMap.addMarker(markerOptions);

            // Locate the first location
            if (i == 0) {
                CameraUpdate center = CameraUpdateFactory.newLatLng(latLng);
                CameraUpdate zoom = CameraUpdateFactory.zoomTo(13);

                googleMap.moveCamera(center);
                googleMap.animateCamera(zoom);
            }

        }

    }
}

public static LatLng getLocationFromString(String address)
    throws JSONException {

    HttpGet httpGet = new HttpGet(
        "http://maps.google.com/maps/api/geocode/json?address="
                + URLEncoder.encode(address, "UTF-8") + "&ka&sensor=false");
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    try {
    response = client.execute(httpGet);
    HttpEntity entity = response.getEntity();
    InputStream stream = entity.getContent();
    int b;
    while ((b = stream.read()) != -1) {
        stringBuilder.append((char) b);
    }
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

    JSONObject jsonObject = new JSONObject(stringBuilder.toString());

    double lng = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
        .getJSONObject("geometry").getJSONObject("location")
        .getDouble("lng");

    double lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
        .getJSONObject("geometry").getJSONObject("location")
        .getDouble("lat");

    return new LatLng(lat, lng);
}

    public static List<Address> getStringFromLocation(double lat, double lng)
    throws ClientProtocolException, IOException, JSONException {

    String address = String
        .format(Locale.ENGLISH,                                 "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=true&language="
                        + Locale.getDefault().getCountry(), lat, lng);
    HttpGet httpGet = new HttpGet(address);
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    List<Address> retList = null;

    response = client.execute(httpGet);
    HttpEntity entity = response.getEntity();
    InputStream stream = entity.getContent();
    int b;
    while ((b = stream.read()) != -1) {
    stringBuilder.append((char) b);
    }

    JSONObject jsonObject = new JSONObject(stringBuilder.toString());

    retList = new ArrayList<Address>();

    if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {
    JSONArray results = jsonObject.getJSONArray("results");
    for (int i = 0; i < results.length(); i++) {
        JSONObject result = results.getJSONObject(i);
        String indiStr = result.getString("formatted_address");
        Address addr = new Address(Locale.getDefault());
        addr.setAddressLine(0, indiStr);
        retList.add(addr);
    }
    }

    return retList;
}

यह मेरे लिए बहुत अच्छा काम किया है क्योंकि जब जियोकोडर काम नहीं, मैं गूगल मैप्स के लिए सीधी पहुँच का उपयोग करें।

चीयर्स!

27/03/2015 को 13:21
का स्रोत उपयोगकर्ता

वोट
0

निम्न पंक्ति के लिए

Geocoder gCoder = new Geocoder(context, Locale.getDefault());

का प्रयोग करें Context, आपके गतिविधि की और उपयोग नहीं करतेgetApplicationContext()

01/03/2017 को 10:53
का स्रोत उपयोगकर्ता

वोट
0

मैं भी इस त्रुटि के साथ मुसीबत पड़ा है। जब मैं हाल ही में Marshmallow करने के लिए अपने डिवाइस को अद्यतन किया।

अगर मैं रिबूट, यह एक बार में काम करता है, लेकिन फिर असफल हो जायेगी, और सभी उसके बाद से काम नहीं।

मैं अन्य लोगों की तरह एक AsyncTask बनाया है, कि केवल json प्रतिक्रिया के पहले परिणाम से पता देता है।

नीचे दिए गए कोड का उपयोग करने के लिए, फोन इसे अपने api कुंजी के साथ निर्माण किया है, और आप इनपुट AsyncTask निष्पादित करने के लिए के रूप में एक स्थान वस्तु का उपयोग करें। आप निम्नलिखित के साथ स्थान आयात कर सकते हैं। import android.location.Location;आप LocationManager के साथ वर्तमान स्थान प्राप्त करने के लिए, यह करने के लिए एक अद्यतन अनुरोध द्वारा होगा।

    new ReverseGeoCodeTask(GOOGLE_API_KEY).execute(location);

सुनिश्चित करें कि आप अपने खुद के साथ api कुंजी की जगह बनाओ, और भी आप Google क्लाउड कंसोल में सक्षम सुनिश्चित करें। यही कारण है कि जहां आप अपने विशेष परियोजना के लिए सभी को Google API का प्रबंधन है।

गतिविधि है कि आप रिवर्स जिओकोड पते की आवश्यकता होगी, कर रहे हैं में एक इनर क्लास के रूप में इस वर्ग को कॉपी करें।

/**
 * Reverse geocode request - takes a Location in as parameters,
 * and does a network request in the background to get the first address in
 * json response. The address is returned in the onPostExecute so you
 * can update the UI with it
 */

private class ReverseGeoCodeTask extends AsyncTask<Location, Void, String>{

    private final static String GEOCODE_API_ENDPOINT_BASE = "https://maps.googleapis.com/maps/api/geocode/json?latlng=";
    private final static String JSON_PROPERTY_RESULTS = "results";
    private final static String JSON_PROPERTY_FORMATTED_ADDRESS = "formatted_address";
    private final static String JSON_PROPERTY_REQUEST_STATUS = "status";
    private final static String STATUS_OK = "OK";
    private String apiKey;

    public ReverseGeoCodeTask(final String apiKey){
        this.apiKey = apiKey;
    }

    @Override
    protected String doInBackground(Location... params) {

        if(apiKey == null){
            throw new IllegalStateException("Pass in a geocode api key in the ReverseGeoCoder constructor");
        }

        Location location = params[0];
        String googleGeocodeEndpoint = GEOCODE_API_ENDPOINT_BASE + location.getLatitude() + "," + location.getLongitude() + "&key=" + apiKey;
        Log.d(TAG, "Requesting gecoding endpoint : " + googleGeocodeEndpoint);
            try {
                URL url = new URL(googleGeocodeEndpoint);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                StringBuilder result = new StringBuilder();
                String line;
                while ((line = reader.readLine()) != null) {
                    result.append(line);
                }

                JSONObject json = new JSONObject(result.toString());
                String requestStatus = json.getString(JSON_PROPERTY_REQUEST_STATUS);
                if(requestStatus.equals(STATUS_OK)){
                    JSONArray results = json.getJSONArray(JSON_PROPERTY_RESULTS);
                    if(results.length() > 0){
                        JSONObject result1 = results.getJSONObject(0);
                        String address =  result1.getString(JSON_PROPERTY_FORMATTED_ADDRESS);
                        Log.d(TAG, "First result's address : " + address );
                        return  address;


                    }
                    else{
                        Log.d(TAG, "There were no results.");
                    }
                }
                else{
                    Log.w(TAG, "Geocode request status not " + STATUS_OK + ", it was " + requestStatus );
                    Log.w(TAG, "Did you enable the geocode in the google cloud api console? Is it the right api key?");
                }


            }catch ( IOException | JSONException e){

                e.printStackTrace();
            }

        return null;
    }

    @Override
    protected void onPostExecute(String address) {
        super.onPostExecute(address);
        if(address != null){
            // update the UI here with the address, if its not null
            originEditText.setText(address);
        }
        else{
            Log.d(TAG, "Did not find an address, UI not being updated");
        }

    }
}
02/09/2017 को 20:26
का स्रोत उपयोगकर्ता

वोट
0
new Volly_Services(map, "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" + mBinding.loc.getText().toString().trim() + "&key=Ap", getActivity()).vollyPostService().continueWithTask(task - > {
    mBinding.progressBaar.setVisibility(View.GONE);

    if (task.getResult() != null) {

        Log.e("<<<", "" + task.getResult());

        JSONObject jsonObject = new JSONObject("" + task.getResult());
        if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {
            JSONArray results = jsonObject.getJSONArray("results");
            if (results.length() > 0) {
                mBinding.loc.setVisibility(View.GONE);
                for (int i = 0; i < results.length(); i++) {
                    JSONObject result = results.getJSONObject(i);
                    String indiStr = result.getString("formatted_address");
                    Address addr = new Address(Locale.getDefault());

                    addr.setAddressLine(0, indiStr);
                    addr.setLocality(result.getString("name"));
                    JSONObject geometry = result.getJSONObject("geometry").getJSONObject("location");
                    addr.setLatitude(geometry.getDouble("lat"));
                    addr.setLongitude(geometry.getDouble("lng"));


                    addresses.add(addr);
                }
                adapter = new SerchLocationAdapter(getActivity(), addresses);
                mBinding.serchreg.setAdapter(adapter);
            } else {
                Toast.makeText(getActivity(), "No result found", Toast.LENGTH_LONG).show();
            }

        } else {
            Toast.makeText(getActivity(), "No result found", Toast.LENGTH_LONG).show();
        }
    } else {
        Log.e("<<<<<<", "" + task.getError().getMessage());
        Toast.makeText(getActivity(), task.getError().getMessage(), Toast.LENGTH_LONG).show();
    }
    return null;
});
23/03/2018 को 12:20
का स्रोत उपयोगकर्ता

वोट
0

पर एक ही मुद्दा था एंड्रॉयड 6 । समस्या में था ऐप अनुमतियां । यहां तक कि अगर नक्शे ठीक से काम करता आप की अनुमति देनी चाहिए "स्थिति प्राप्त करें" अनुमति की गई अनुमतियों को में।

सबसे अच्छा मामले हमेशा इस अनुमति की अनुमति की जांच करने के लिए जब आप परिणाम में जगह प्राप्त करने की उम्मीद है।

मैं जगह से पूरा पता पाने के लिए इस विधि का उपयोग:

public Address getFullAddress(Place place){
    Address address;

    Locale aLocale = new Locale.Builder().setLanguage("en").build();
    Geocoder geocoder = new Geocoder(this, aLocale);

    try {
        List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude,place.getLatLng().longitude, 1);

        address = addresses.get(0);

        return address;

    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}
04/05/2019 को 17:22
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more