mardi 2 mai 2017

Can't Reading Location Address Line from Google Map on Huawei Devices

I've built location picker (get location address line from google map) to read user location .. its working on all device except Huawei Devices !

Below is my source code to fetch the address address .. appreciate any help .

Thx in advance :)

ProgressDialogFragment.show(MapsActivity.this);
                myLocation = mMap.getCameraPosition().target;
                Bundle b = new Bundle();
                b.putString("Address", getAddress(myLocation));
                b.putString("Latitude", String.valueOf(myLocation.latitude));
                b.putString("Longitude", String.valueOf(myLocation.longitude));
                Intent i = getIntent(); 
                i.putExtras(b);
                setResult(Activity.RESULT_OK, i);
                ProgressDialogFragment.hide(MapsActivity.this);

//////////////////////

 private String getAddress(LatLng latLng) {
    Geocoder geocoder;
    List<Address> addresses = null;
    geocoder = new Geocoder(MapsActivity.this, new Locale("ar"));
    String address = "";
    try {
        addresses = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1); 
        int addresslines = addresses.size();
        for (int i = 0; i < addresslines; i++) {
            if (addresses.get(i).getThoroughfare() != null) {
                address += addresses.get(i).getThoroughfare() + " , ";
            }
            if (addresses.get(i).getSubLocality() != null) {
                address += addresses.get(i).getSubLocality() + " , ";
            }
            if (addresses.get(i).getLocality() != null) {
                address += addresses.get(i).getLocality() + " , ";
            }
            if (addresses.get(i).getCountryName() != null) {
                address += addresses.get(i).getCountryName() + " , ";
            }
        }
        if (address.length() > 0)
            address = address.substring(0, address.length() - 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return address;
}

Aucun commentaire:

Enregistrer un commentaire