Reputation: 593
I have this mistake when I try to run my application: "this app won't run unless you update google play services"
I have tried many things that are here, but nothing. I've generated the application with the assistance of Android Studio. I have download the rev 22 to Google Play Services and rev 12 of Google Play services for Froyo My proyect is Api 17 and when I run the project in the phone, it's display ok.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemaps.googlemaps" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity
package com.example.googlemaps.googlemaps;
import android.app.Dialog;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMyLocationChangeListener {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!=ConnectionResult.SUCCESS){
int requestCode=10;
Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
else{
SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mMap=fm.getMap();
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationChangeListener(this);
}
}
@Override
public void onMyLocationChange(Location location) {
// TODO Auto-generated method stub
// TextView tvLocation=(TextView)findViewById(R.id.textView1);
double latitude=location.getLatitude();
double longitude=location.getLongitude();
LatLng latLng=new LatLng(latitude,longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// tvLocation.setText("Latitude:"+latitude+", Longitude:"+longitude);
}
}
Upvotes: 0
Views: 3942
Reputation: 3711
Good news for you. Google now provides a standalone library for maps which, at the time of writing this post, is in beta
The Maps SDK for Android is now distributed via a standalone static library. Previously, the Maps SDK for Android was made available as part of Google Play services
https://developers.google.com/maps/documentation/android-sdk/v3-client-migration
Upvotes: 0
Reputation: 4037
The error you are getting is because you are not running the updated version of Google Play Services that is 6.5. Make sure you have added that in your build.gradle file as dependencies. Add the following lines.
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
If you are using your app just for maps you can selectively add:
com.google.android.gms:play-services-maps:6.5.87
Please refer to this documentation for more details.
Assuming that you have replaced the API_KEY in your manifest file with your actual API key, you should be able to see the maps running on your app without getting any error.
For more details read official documentation on Google Play Services 6.5.
Upvotes: 2