Reputation: 3789
I am working on integrating google maps in a small app. My AndroidManifest.xml
is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymaps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.mymaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature android:glEsVersion="0x00020000"/>
<uses-feature android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mymaps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MyKey" />
</application>
</manifest>
And my Main Activity is
public class MainActivity extends Activity implements OnClickListener {
TextView lat,lng;
Button getCds,getMap;
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeVars();
}
private void initializeVars() {
// TODO Auto-generated method stub
getCds = (Button)findViewById(R.id.bGC);
getMap = (Button)findViewById(R.id.bGM);
lat = (TextView)findViewById(R.id.TextView2);
lng = (TextView)findViewById(R.id.TextView4);
getCds.setOnClickListener(this);
getMap.setOnClickListener(this);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
public void onClick(View v) {
Log.d("Debugging", "I am in onCLick");
switch (v.getId()) {
case R.id.bGC:
{
Log.d("Debugging", "I am in case R.id.bGC");
lat.setText("My Lat");
lng.setText("My Long");
break;
}
case R.id.bGM:
{
Log.d("Debugging", "I am in case R.id.bGM");
lat.setText("blank");
lng.setText("blank");
break;
}
}
}
}
When I Load the application I am getting the below error.
01-17 14:01:49.054: E/Google Maps Android API(2832): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-17 14:01:49.064: E/Google Maps Android API(2832): Ensure that the following correspond to what is in the API Console: Package Name: com.example.mymaps, API Key: MyKey, Certificate Fingerprint: SomeValue
01-17 14:01:49.064: I/Google Maps Android API(2832): Failed to contact Google servers. Another attempt will be made when connectivity is established.
01-17 14:01:59.234: D/dalvikvm(2832): GC_CONCURRENT freed 572K, 9% free 7576K/8263K, paused 6ms+3ms
01-17 14:02:04.304: E/Google Maps Android API(2832): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Guys to give a little more perspective. The same code used to work before (probably 3-4 months back). It somehow doesn't seem to be working anymore. I am not sure what is causing the same.
Can you please advise how to debug the same?
Upvotes: 0
Views: 215
Reputation: 13223
The your.package.name.permission.MAPS_RECEIVE
is no longer needed. Please remove it from your manifest. Also you are missing this:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
It should be added within the <application>
tag.
Upvotes: 0
Reputation: 5260
have a change from
<uses-permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
to
<uses-permission
android:name="com.example.mymaps.permission.MAPS_RECEIVE" />
I think the problem is with the key and it is not the correct one which you are using, Your API key in your manifest clearly does not match the API key you posted that is showing in the API console. Paste the API key from the console into the manifest. Should fix you right up.
you can uninstall the app, and do a project clean, then re-install the app.. have a try with this but still it does not works than
for more please visit for the complete process for using new google map
http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/
http://www.learn2crack.com/2013/12/android-google-maps-api-v2-example.html
The best tutorial is
http://codebybrian.com/2012/12/06/google_maps_android_v2_sample.html
Upvotes: 1