Henry
Henry

Reputation: 1042

cannot resolve symbol 'Address' android studio

I am using this link How to find postcode by latitude and logitude for UK and this link Get current location using GPS in Android to get user lat and long and then convert it into post code. However, I am getting an error on Address, it says cannot resolve symbol 'Address' android studio and because of this address= geoCoder.getFromLocation(latitude, longitude, 1); and this String postCode = address.get(0).getPostalCode(); line.

    Geocoder geoCoder = new Geocoder(getActivity().getApplicationContext(), Locale.getDefault());
            List<Address> address = null;

            if (geoCoder != null){
                try {
                    address= geoCoder.getFromLocation(latitude, longitude, 1);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                if (address.size()> 0){
                    String postCode = address.get(0).getPostalCode();
                }

If you can help, it would be really nice. I am new to android and have no clue on how to go about solving this. If my question is not clear please let me know.

EDITED:

premission in manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Gradel compile

 compile 'com.google.android.gms:play-services:4.3.23'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:support-v4:23.0.1'

Upvotes: 0

Views: 2501

Answers (2)

Henry
Henry

Reputation: 1042

Solved my problem, it turned out that I had to import

import android.location.Address;

Upvotes: 3

Shmuel
Shmuel

Reputation: 3916

Try updating play services to the latest version 8.4.0

 dependencies {
    compile 'com.google.android.gms:play-services:8.4.0'
 }

https://developers.google.com/android/guides/setup

Upvotes: 1

Related Questions