The import com.google.android.gms.location.LocationClient cannot be resolved after formatting computer
Asked Answered
P

3

6

I formatted my computer and again imported my android project which has been done using Google Maps API V2 and found out many errors.I re-linked google_play_services_lib and android-support-v7-appcompat.I still find an error in importing com.google.android.gms.location.LocationClient.Only the call of "LocationClient" gives an error and others are imported fine.

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
(ERROR)import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

and find errors everywhere I have used R. calling. error : R cannot be resolved to a variable

setContentView(R.layout.activity_main); EditText et = (EditText) findViewById(R.id.editText1);

and getting the following errors in the console.

[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:121: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:119: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:116: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:117: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:155: error: Error: No resource found that matches the given name: attr 'android:colorAccent'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:157: error: Error: No resource found that matches the given name: attr 'android:colorControlActivated'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:158: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:156: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:153: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:154: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:192: error: Error: No resource found that matches the given name: attr 'android:colorAccent'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:194: error: Error: No resource found that matches the given name: attr 'android:colorControlActivated'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:195: error: Error: No resource found that matches the given name: attr 'android:colorControlHighlight'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:193: error: Error: No resource found that matches the given name: attr 'android:colorControlNormal'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:190: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.
[2014-12-19 23:22:44 - MapsProject] 
[2014-12-19 23:22:44 - MapsProject] C:\Users\Sudesh\Android_Workspace\android-support-v7-appcompat\res\values-v21\themes_base.xml:191: error: Error: No resource found that matches the given name: attr 'android:colorPrimaryDark'.
[2014-12-19 23:22:44 - MapsProject] 
Polyzoarium answered 19/12, 2014 at 18:34 Comment(1)
See this question for how to switch your application to FusedLocationProviderApi.Heartbreak
S
14

LocationClient was deprecated a while ago and apparently was removed from Play Services recently. You will need to switch to using GoogleApiClient to get the LocationServices.API. This sample project demonstrates how to do this. Basically:

Step #1: Set up a GoogleApiClient data member of whatever is using the API:

private GoogleApiClient client=null;

Step #2: Request the LocationServices.API:

client=new GoogleApiClient.Builder(host)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

Step #3: In onConnected() of your GoogleApiClient.ConnectionCallbacks, start using LocationServices.FusedLocationApi to work with locations (e.g., call getLastLocation())

Stoll answered 19/12, 2014 at 18:37 Comment(6)
what's with the errors in setContentView(R.layout.activity_main); EditText et = (EditText) findViewById(R.id.editText1); R Cannot Be resolved to a variablePolyzoarium
@SNT93: You appear to be using appcompat-v7, and so you need to set your build target (e.g., Project > Properties > Android) to API Level 21 or higher. That has nothing to do with LocationClient.Stoll
@SNT93: I would recommend that you look at the sample project that I linked to in my answer. There is also this blog post and various other Stack Overflow answers like this one. Unfortunately, Google has not documented this stuff yet, so I cannot point you at docs.Stoll
How can I start a map using GoogleAPIClient Previously i used if(initMap()) {mLocationClient = new LocationClient(this,this,this); mLocationClient.connect();} else { Toast.makeText(this,"Map Not Available!",Toast.LENGTH_SHORT).show(); }Polyzoarium
@SNT93: That code does not start a map. You would do much the same thing here, just with the GoogleApiClient stuff in your if block.Stoll
Have I done right ? #27580091Polyzoarium
O
0

Did you import the google play library in the same folder? I mean when importing there is an option copy project to the existing workspace. Check it when importing. enter image description here

Obel answered 19/12, 2014 at 18:44 Comment(1)
yes I did that.Both the references are having green ticksPolyzoarium
S
0

From https://developers.google.com/android/guides/api-client:

When you want to make a connection to one of the Google APIs provided in the Google Play services library (such as Google+, Games, or Drive), you need to create an instance of GoogleApiClient ("Google API Client"). The Google API Client provides a common entry point to all the Google Play services and manages the network connection between the user's device and each Google service.

Stockroom answered 17/1, 2015 at 22:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.