Reputation: 10059
I am using a Google Api 19.
I am getting the Stacktrace error at runtime while running the Google map V2. Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
StackTrace:
E/Random(2450) : > 17.384058210414967, 78.48609545247936
E/Random(2450) : > 17.385480575802443, 78.48634970995319
E/Random(2450) : > 17.384707320313552, 78.48718165182942
E/Random(2450) : > 17.384469518257607, 78.48737972822704
E/Random(2450) : > 17.386012910991372, 78.48664538492055
E/Random(2450) : > 17.384268963692328, 78.48682608163563
E/Random(2450) : > 17.385942881352822, 78.48616019819285
E/Random(2450) : > 17.384971626221553, 78.48736770924768
E/Random(2450) : > 17.384794739104553, 78.48631955135781
E/Random(2450) : > 17.38564903886939, 78.48614895429334
D/gralloc_goldfish(2450): Emulator without GPU emulation detected.
I/Choreographer(2450) : Skipped 621 frames! The application may be doing too much work on its main thread.
E/Google Maps Android API(2450): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.googlemapsv2"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<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"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="info.androidhive.googlemapsv2.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB2p7rsFLCuYmjA8SnRsIZfjWugwgh4wtU" />
</application>
</manifest>
MainActivity.java:
package com.map.googlemap;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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.MarkerOptions;
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
// Changing map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Showing / hiding your current location
googleMap.setMyLocationEnabled(true);
// Enable / Disable zooming controls
googleMap.getUiSettings().setZoomControlsEnabled(false);
// Enable / Disable my location button
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
// Enable / Disable Compass icon
googleMap.getUiSettings().setCompassEnabled(true);
// Enable / Disable Rotate gesture
googleMap.getUiSettings().setRotateGesturesEnabled(true);
// Enable / Disable zooming functionality
googleMap.getUiSettings().setZoomGesturesEnabled(true);
double latitude = 12.987100;
double longitude = 80.251692;
// lets place some 10 random markers
for (int i = 0; i <1; i++) {
// random latitude and logitude
double[] randomLocation = createRandLocation(latitude,
longitude);
// Adding a marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(randomLocation[0], randomLocation[1]))
.title("Hello Maps " + i);
Log.e("Random", "> " + randomLocation[0] + ", "
+ randomLocation[1]);
// changing marker color
if (i == 0)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
if (i == 1)
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
googleMap.addMarker(marker);
// Move the camera to last position with a zoom level
if (i == 0) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(randomLocation[0],
randomLocation[1])).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
/**
* function to load map If map is not created it will create it for you
* */
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();
}
}
}
private double[] createRandLocation(double latitude, double longitude) {
return new double[] { latitude + ((Math.random() - 0.5) / 500),
longitude + ((Math.random() - 0.5) / 500),
150 + ((Math.random() - 0.5) * 10) };
}
}
Output:
I doesn't know how to solve these stackTrace Error.Anybody can help me with these.Thank You.
Upvotes: 2
Views: 2970
Reputation: 656
For me the issue was in that I have used network_security_config setting in Manifest under the application tag.
I am still not sure how to handle it correctly but after I just removed that setting (occasionally it wasn`t needed for my project) Maps become to work.
Upvotes: 0
Reputation: 10059
I solved these problem by doing the following steps:
In Emulator:
You have to use the latest API Google APIs(Google Inc.)-API Level
19
.
Do the rest of the things placed in the screenshot itself.
API Key:
Create New API Key and Check carefully about Google Map API key and SHA Key.
Google Play Services:
You have to download the latest Google Play Services
com.android.vending-4.8.20.apk.In that site if google play
services wasn't working means you can find a lot of sites in
internet named com.android.vending 4.8.20.apk
.
you can run the Google play Services by using the Command Prompt
adb install com.android.vending 4.8.20.apk
.
Note: You have to download the latest Google play services because year by year latest version will be updated in internet.
output:
Upvotes: 1