0

I would like to ask about a strange situation, that happened during usage of Google Maps API v2. There is an error in logcat that says:

The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

The things that I have:

  • Google Map is displayed perfectly along with markers - I have acquired relevant code from Google.
  • google-play-services.jar library is included perfectly with Eclipse (project->properties->android->add...).
  • The checkboxes in Eclipse (project->properties->java build path->order build path) are all checked properly.
  • The code GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); returns true.
  • This code is running at a device, Nexus 4, not emulator.

I am trying to invoke event, that would allow me to get current position by this class:

public class FindMyLocationManager implements LocationListener, LocationSource
{
    private OnLocationChangedListener mListener;
    private LocationManager locationManager;
    private GoogleMap map;
    private Context ctx;
    private int intervalTime;
    private int intervalDistance;


    public void setMap(GoogleMap map)
    {
        this.map = map;
    }


    public int getIntervalTime()
    {
        return intervalTime;
    }


    public void setIntervalTime(int intervalTime)
    {
        this.intervalTime = intervalTime;
    }


    public int getIntervalDistance()
    {
        return intervalDistance;
    }


    public void setIntervalDistance(int intervalDistance)
    {
        this.intervalDistance = intervalDistance;
    }


    public FindMyLocationManager(Context mContext)
    {
        this.ctx = mContext;
        locationManager = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
    }


    @Override
    public void activate(OnLocationChangedListener listener)
    {
        mListener = listener;
        isGooglePlayOk(); //returns true
        if(isGPSAvailable())
        {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, intervalTime, intervalDistance, this);
        }
        else if(isCompassAvailable())
        {
            Log.d("DEBUG", "No GPS here");
        }
        else
        {
            Log.d("DEBUG", "Nothing here");
        }
    }


    private boolean isGPSAvailable()
    {

        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }


    public boolean isGooglePlayOk()
    {
        int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx);

        if(isAvailable == ConnectionResult.SUCCESS)
        {
            Toast.makeText(ctx, "Can connect to Goolge Play", Toast.LENGTH_SHORT).show();

            return true;
        }
        else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable))
        {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, (Activity)ctx, 9001);
            dialog.show();

        }
        else
        {
            Toast.makeText(ctx, "Can't connect to Goolge Play", Toast.LENGTH_SHORT).show();
        }
        return false;
    }


    private boolean isCompassAvailable()
    {
        PackageManager pm =
                ctx.getPackageManager();

        return pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
    }


    @Override
    public void deactivate()
    {
        locationManager.removeUpdates((android.location.LocationListener)this);
        mListener = null;
    }


    public void restart()
    {
        locationManager.removeUpdates((android.location.LocationListener)this);
        if(isGPSAvailable())
        {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, intervalTime, intervalDistance, this);
        }
        else if(isCompassAvailable())
        {
            Log.d("DEBUG", "No GPS");
        }
        else
        {
            Log.d("DEBUG", "Nothing at all");
        }
    }

    // the compiler never enters here
    @Override
    public void onLocationChanged(Location location)
    {
        Toast.makeText(this.ctx, location.getLatitude() + " " + location.getLongitude(), Toast.LENGTH_LONG).show();
        if(mListener != null)
        {
            mListener.onLocationChanged(location);
        }

        map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
    }


    @Override
    public void onProviderDisabled(String arg0)
    {
        // TODO Auto-generated method stub

    }


    @Override
    public void onProviderEnabled(String arg0)
    {
        // TODO Auto-generated method stub

    }


    @Override
    public void onStatusChanged(String arg0, int arg1, Bundle arg2)
    {
        // TODO Auto-generated method stub

    }
}

And here is the usage of above code:

// this method is called in many places in the program, like onCreate of my view with map or onResume
    private void setUpMapIfNeeded()
        {
            if(map == null)
            {
                map = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
                if(map != null)
                {
                    map.setMyLocationEnabled(true);
                    locationManager.setMap(map);
                    locationManager.setIntervalDistance(0);
                    locationManager.setIntervalTime(0);
                    map.setLocationSource(locationManager); //Here I apply the object from above class
                    //if(currentModel != null)
                    //currentModel = getCurrentModel(); TODO
                    //moveCameraInstantly(map.);
                    focusCamera();
                    fillMapWithMarkers(FindMyApplication.MAP_MARKER_MODELS);
                }
            }
    }

UPDATE

So it seems that the error itself is harmless, but I still don't get the onLocationChanged event.


UPDATE 2

This code is based on How to get My Location changed event with Google Maps android API v2? .

Community
  • 1
  • 1
DreamOnJava
  • 635
  • 6
  • 12
  • check the answer here: http://stackoverflow.com/questions/18068627/logcat-message-the-google-play-services-resources-were-not-found-check-your-pr – Igor K Jan 03 '14 at 14:41
  • you should be using the new `Fused location API` and not the old one – tyczj Jan 03 '14 at 15:12
  • @tyczj I am now using Google Maps For Froyo, because of my android version (2.2, API 8), but I will try that API You mentioned. – DreamOnJava Jan 03 '14 at 15:38
  • @DreamOnJava it is also in that version too – tyczj Jan 03 '14 at 15:39

3 Answers3

1

If i understand correctly you have defined the location update method, but have not started requesting the location updates.

To send the request for location updates, create a location client and a request in onCreate():

protected void onCreate(Bundle savedInstanceState) {
  ...
  mLocationClient = new LocationClient(this, this, this);
  mLocationRequest = LocationRequest.create();
}

Then connect it in onStart():

protected void onStart() {
    ...
    mLocationClient.connect();
}

Then make the update request in onConnected():

public void onConnected(Bundle dataBundle) {
    ...
    mLocationClient.requestLocationUpdates(mLocationRequest, this);
}

Here is a complete guide on how to do this correctly: http://developer.android.com/training/location/receive-location-updates.html#StartUpdates

The Google Play services resources were not found. error is a common bug in the library.

nillas
  • 431
  • 3
  • 4
0

EDIT Also this piece of code seems suspicious:

if(map == null) {
            map = <something new>;
            if(map != null) {
                <do thing>
            }
}

Is your map always null before entering this method?

EDIT2

map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
         @Override
         public void onMyLocationChange(Location location) {
             Log.d("DEBUG", "setOnMyLocationChangeListener");
             setUpMapIfNeeded();
         }
});

if it doesn't work, then try also:

map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
     @Override
     public onCameraChange(CameraPosition cameraPosition) {
         Log.d("DEBUG", "setOnCameraChangeListener");
         setUpMapIfNeeded();
     }
});

I need log results on this.

Igor K
  • 470
  • 6
  • 10
  • The error disappeared but the location event still does not fire. – DreamOnJava Jan 03 '14 at 14:52
  • But does isGPSAvailable() return true? – Igor K Jan 03 '14 at 14:59
  • Please, revert change. Your question isn't defined clearly. As I understood onLocationChanged() event isn't called, correct? Your log and method sequence can be really helpful to resolve problem. – Igor K Jan 03 '14 at 15:11
  • Also with provided code isn't enough to reproduce your problemfor me. I usually use map.setOnCameraChangeListener() and/or map.setOnMyLocationChangeListener in my application. – Igor K Jan 03 '14 at 15:39
  • There is absolutely nothing in the log - no errors whatsoever after deleting that line. So log wouldn't be helpful here. I will post method sequence though. – DreamOnJava Jan 03 '14 at 15:40
  • My code is based on this: http://stackoverflow.com/questions/13742551/how-to-get-my-location-changed-event-with-google-maps-android-api-v2 – DreamOnJava Jan 03 '14 at 15:41
  • BTW, I'm getting onLocationChanged() method fired constantly on Samsung Galaxy Ace 2 I8160. – Igor K Jan 03 '14 at 15:46
  • above link says, that this method, with onMyLocationChangeListener is deprecated. – DreamOnJava Jan 03 '14 at 15:48
0

if the map shows like it should then you did everything correctly, there is something in the library that is causing the problem that google needs to fix. I get this error in my app even when I dont use google maps.

since you have google play service you should be using the new location API and not the old one.

http://developer.android.com/training/location/index.html

tyczj
  • 71,600
  • 54
  • 194
  • 296