I'm working on a project which involves a "Points of Interest" locator. I have a generated Google Maps API v2 key and I've added all the proper permissions to the AndroidManifest (as you'll see below), and everything compiles...except for the map itself! There's a marker that shows your current location and as well as the GPS coordinates but not the map, which needless to say is essential. Also there are no runtime erros except that the LogCat says at points "There is too much output to process". Any help would be greatly appreciated.
Android Manifest
package="com.example.kavin_000.travelapplication" >
<!-- suppress AndroidDomInspection -->
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<permission
android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/nyit_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".ow_main_page"
android:label="#string/app_name" >
</activity>
<activity
android:name=".manhattan_main_page"
android:label="#string/title_activity_manhattan_main_page" >
</activity>
<activity
android:name=".main_page"
android:label="Travel Application" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ow_campus_points_of_interest"
android:label="#string/title_activity_ow_campus_points_of_interest" >
</activity>
<activity
android:name=".manhattan_campus_points_of_interest"
android:label="#string/title_activity_manhattan_campus_points_of_interest" >
</activity>
<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="MY_KEY" />
</application>
</manifest>
Layout XML file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".ow_main_page"
android:background="#ffffb502">
<fragment
android:id="#+id/googleMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_above="#+id/latlongLocation" />
<TextView
android:id="#+id/latlongLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:background="#ff058fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#ffffffff"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
</RelativeLayout>
Java class in question
package com.example.kavin_000.travelapplication;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;
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.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class ow_campus_points_of_interest extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//show error dialog if GooglePlayServices not available
if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.activity_ow_campus_points_of_interest);
SupportMapFragment supportMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
}
#Override
public void onLocationChanged(Location location) {
TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}
}
It sounds like there may be an issue with your authorization on Google App Engine. Did you make sure to use the SHA1 fingerprint from your debug.keystore and not from your release keystore? Additionally, make sure that you are appending ;com.example.kavin_000.travelapplication to the end of the SHA1 fingerprint.
If you have not added your SHA1 fingerprint to the list of authorized applications, that is the issue. It can be done by finding your debug.keystore file (search on Google depending on your OS), and running the following command:
keytool -list -v -keystore debug.keystore
Related
I'm just trying to see a map in my android app and i'm having some troubles.
I've been following severals tutorial and still a have no result.
I downloaded google play services from my sdk manager and imported google_play_services_lib correctly i guess.
So i created a Google Maps API Key from Google Api Console using my packagename and my SHA1, which i found using cmd and also in eclipse in window>preferences>android>build, i got the same SHA1 in both ways so i think it's correct.
So i set my manifest like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapprova"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<permission android:name="com.example.googlemapprova.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlemapprova.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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.maps.v2.API_KEY"
android:value="my api key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".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>
</application>
in my layout file i created just a map fragment
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/textView1"
android:layout_centerHorizontal="true" />
I've changed android:name with class="com.google.android.gms.maps.SupportMapFragment" because of a tutorial
And then my main
package com.example.googlemapprova;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
initializeUiSettings();
initializeMapLocationSettings();
initializeMapTraffic();
initializeMapType();
initializeMapViewSettings();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
protected void onResume() {
super.onResume();
// initilizeMap();
}
private void initilizeMap() {
googleMap = ((SupportMapFragment) getSupportFragmentManager().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();
}
}
public void initializeUiSettings() {
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(false);
googleMap.getUiSettings().setTiltGesturesEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
}
public void initializeMapLocationSettings() {
googleMap.setMyLocationEnabled(true);
}
public void initializeMapTraffic() {
googleMap.setTrafficEnabled(true);
}
public void initializeMapType() {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
public void initializeMapViewSettings() {
googleMap.setIndoorEnabled(true);
googleMap.setBuildingsEnabled(false);
}
}
i got the code in my main from a tutorial and modified it just a little, in this way i managed my app to not crash(if i don't use this code my app will crash).
this is what i get
i'm using a motorola moto g3 phone to try it
So i tryed to download aLogcat on my phone from play store, but i get nothing on it, maybe i'm using it in the wrong way.
this is the tutorial i used the most
Can someone help me to view a map on my app? I can't understand why it's not working
I'm trying to get the Logcat now
Your map fragment is loaded, but map content does not.
Where you placed your API key?
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key" />
I need some help...
My application can't show the map. I've enabled the API Key and try to create it many times, with new keystore.
Screenshot for result
The error code says:
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/b: Authentication failed on the server.
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: Authorization failure. Please see
12-14 03:47:45.533 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs
Android Application (<cert_fingerprint>;<package_name>): 39:AD:91:AB:60:3D:34:22:1C:F3:36:4B:B6:98:6F:BB:61:5A:B5:60;tkj5a.dhiaulhaq.pnj.project_paksyamsi
And my layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tkj5a.dhiaulhaq.pnj.project_paksyamsi">
<permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".CheckInActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
</application>
</manifest>
And here's the MapsActivity.java:
package tkj5a.dhiaulhaq.pnj.project_paksyamsi;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
public class MapsActivity extends FragmentActivity {
private GoogleMap map;
private DBLokasi lokasi;
private ArrayList<DBLokasi> values;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFrag=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map=mapFrag.getMap();
map.setMyLocationEnabled(true);
Bundle b=this.getIntent().getExtras();
if (b.containsKey("longitude")){
final LatLng latLng=new LatLng(b.getDouble("latitude"),b.getDouble("longitude"));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this,"Lokasi Saat Ini " + latLng.latitude+ "," +latLng.longitude,Toast.LENGTH_LONG).show();
return false;
}
});
}else if (this.getIntent().getSerializableExtra("lokasi")!=null){
lokasi=(DBLokasi)this.getIntent().getSerializableExtra("lokasi");
if (lokasi!=null){
LatLng latLng=new LatLng(lokasi.getLatD(),lokasi.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)).title(lokasi.getNama()));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name),marker.getTitle()));
tvKoordinat.setText(marker.getPosition().latitude+ ","+ marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
else {
LatLng init;
DBLokasi lokInit;
LatLng latLng;
values=((ArrayList<DBLokasi>)this.getIntent().getSerializableExtra("arraylokasi"));
lokInit=values.get(0);
init=new LatLng(lokInit.getLatD(),lokInit.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(init,16));
for (DBLokasi lok:values){
latLng=new LatLng(lok.getLatD(),lok.getLngD());
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name)));
tvKoordinat.setText(marker.getPosition().latitude+","+marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
}
}
Thanks for any helps guys :)
Confirm the SHA-1 key you are getting in the message and the key you have on server are same. Also, make sure adding the API key in manifest as well as in a XML file (release -> res -> values -> google_maps_api.xml) which automatically gets generated.
**Manifest:**
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
and
**google_maps_api.xml**
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR_KEY_HERE
</string>
You can get SHA-1 key and package name from the error message you have posted. Both are separated by ';'
Make sure your API key is the correct one... and maybe check if you have the 'Google Play Services' SDK installed.
It says "In the Google Developer Console" so i would start there lol
Check:
-SHA 1 key
-API Key
Don't forget to hit 'Save' once you're done, i know a few people who have made that mistake before!
I'm developing a android app cappable of acessing the maps API, but i'm stuck on error:
Google Maps Android API﹕ Failed to load map. Error contacting Google
servers. This is probably an authentication issue (but could be due to
network errors).
Already did the key and activate everithing in google API console.
These are my files:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hflopes.mapas" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"></uses-permission>
<uses-feature android:glEsVersion="0x00020000"
android:required="true"></uses-feature>
<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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBTObQnY1mxYwXw1g8txH5ApBu8ovxv730" />
<activity android:name=".MostraAlunosProximos"></activity>
<activity
android:name=".mapas"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
mapas_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mapa"/>
</LinearLayout>
Class for Loading the map:
package hflopes.mapas;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by HFLopes on 24/07/2014.
*/
public class MostraAlunosProximos extends FragmentActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa_layout);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.mapa, new MapaFragment());
transaction.commit();
}
}
Any Idea?
Thanks for the help
I have done the same.
Try this in your MostraAlunosProximos class oncreate,
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if (status != ConnectionResult.SUCCESS) { // Google Play Services
// are
// not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
this, requestCode);
dialog.show();
} else { // Google Play Services are available
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapa);
// Getting GoogleMap object from the fragment
if (fm != null) {
googleMap = fm.getMap();
}
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
}
And add this line android:name="com.google.android.gms.maps.SupportMapFragment" inside fragment of your xml file.
And also i see there are two metadeta for google play service remove that.
Hope this helps
I did this and got to work on my device. Try it.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.example.mapsexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="20"
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<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="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- 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"
android:theme="#style/AppTheme" >
<activity
android:name="br.com.example.mapsexample.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>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key_here" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Class for loading map
package br.com.example.mapsexample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
public class MainActivity extends Activity {
GoogleMap mGoogleMap;
#Override
protected void onCreate( final Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
this.setContentView( R.layout.activity_main );
try {
this.initializeMap();
} catch ( final Exception e ) {
// TODO: handle exception
}
}
#Override
protected void onResume() {
super.onResume();
this.initializeMap();
}
private void initializeMap() {
if ( this.mGoogleMap == null ) {
this.mGoogleMap = ( ( MapFragment ) this.getFragmentManager().findFragmentById( R.id.mapFragment ) ).getMap();
if ( this.mGoogleMap == null ) {
Toast.makeText( this.getApplicationContext(), "Is not possible load the map", Toast.LENGTH_SHORT ).show();
}
}
}
}
Layout Maps
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/mapFragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Solved it!
it was missing this on build.graddle
signingConfigs {
debug {
storeFile file("debug.jks")
}
}
Thanks for the help
Here is Main Activity.java code :
package com.example.vd;
import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
public class MainActivity extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
LatLng myPosition;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1);
googleMap=fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria=new Criteria();
String provider =locationManager.getBestProvider(criteria, true);
Location location=locationManager.getLastKnownLocation(provider);
if(location!=null){
double latitude =location.getLatitude();
double longitude=location.getLongitude();
LatLng latlng=new LatLng(latitude, longitude);
myPosition=new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(myPosition).title("Here"));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
here is activity_main.xml code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
And here is AndroidManifest.xml code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="14" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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"/>
<uses-permission android:name="com.example.vd.permission.MAPS_RECEIVE"/>
<permission android:name="com.example.vd.permission.MAPS_RECEIVE"
/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.vd.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="AIzaSyB5pN0xyJTRLVOAX3scagfb58b0bB0TBwg"/>
</application>
And I'm using Android 4.2.2 and using library google-play-services_lib
I've already search on the Internet and try to fix it for many many times but I still getting this error : Unfortunately application has stopped error.
See here,just change the api key with your key in manifest file and follow these steps:
and make sure that generate api key with package name which is mentioned in android manifest file and your google_play_services_lib project should be present in your project's work space only.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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" >
<activity
android:name="com.geeklabs.map.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="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
After got this let me know.
And make sure following steps done correct or not:
Steps:
* to ensure that device has Google Play services APK
* to install Google Play Service rev. more than 2
to create project at https://code.google.com/apis/console/
to enable "Google Maps Android API v2"
to register of SHA1 in project (NOW, YOU NEED WRITE SHA1;your.app.package.name) at APIs console and get API KEY
to copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project
to add next line to the YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
to add next lines to the YOUR_PROJECT/proguard-project.txt
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Okay, now you ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
Replace your Code
from
SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1);
to
MapFragment fm=(MapFragment)getFragmentManager().findFragmentById(R.id.map1);
Also Add
<permission
android:name="com.xxxxxx.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
For More Details:
Visit: Android Maps V2
I have a project of google map android api v2 but i run this project in my phone a logcat has error
Falied to load map.Error contacting Google servers. This is probable an authentication issue(but could be due to network errors)
so my code is Here
in class HomeActivity
package com.mpa.emvi;
import com.mpa.emvi.R;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
//import android.app.Activity;
import android.view.Menu;
public class HomeActivity extends FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
}
this is a Layout HomeActivity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/send"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".HomeActivity" >
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/sendDS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/map"
android:layout_centerHorizontal="true"
android:text="#string/send_destination"/>
</RelativeLayout>
And this is a Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mpa.emvi"
android:versionCode="2"
android:versionName="2.1.0">
<permission
android:name="com.mpa.emvi.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.mpa.emvi.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="14"/>
<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"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
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.mpa.emvi.HomeActivity"
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="My-Release-API-KEY"/>
</application>
</manifest>
You see my code. What do you thing?
Ok I'm try to seach same issue in this and i try re-generate new api key but not work.
In my project aleady import a google service lib and android support v4.
In google console i open google map android api v2 service.
In google console android apps: my-SHA1-serials;com.mpa.emvi
OK a lasting I'm a newbie android programmer and sorry for my english is poor.
Thank for every Answer.
Have you added your Api key in Manifest File?
Ok now my app is showing the map.I forget delete old apk file and re-install new apk file it work.Thank For Any Answer Thank.