GooglePlayServices[GoogleMap API] - Can't see a map - android

For some reason i can't see any map using the google play services API.
activity_map:
package com.m.get.dl;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class Map extends FragmentActivity implements OnMapReadyCallback
{
MapFragment mapFragment;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fragment_id);
mapFragment.getMapAsync(Map.this);
}
#Override
public void onMapReady(GoogleMap googleMap)
{
googleMap.setMyLocationEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); // Setting map type
}
#Override
protected void onDestroy()
{
// TODO Auto-generated method stub
super.onDestroy();
}
#Override
protected void onPause()
{
// TODO Auto-generated method stub
super.onPause();
}
#Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
}
#Override
protected void onSaveInstanceState(Bundle outState)
{
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
}
#Override
protected void onStop()
{
// TODO Auto-generated method stub
super.onStop();
}
}
I think the problem lies in the XML file - activity_map.xml:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
class="com.google.android.gms.maps.MapFragment"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/fragment_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.m.get.dl"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="23" />
<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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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=".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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="My key" />
<activity
android:name=".Map"
android:label="#string/title_activity_map" >
</activity>
</application>
</manifest>
So in the activity i get this screen instead of a map.
So is my fragment tag is wrong?

Check the server key you are using. Make sure you have used accurate SHA-1 and package name. Rest of the code looks good!
Also, check the log if you are getting any error like:
Authentication failed on the server...
This says your key is not correct.
Updated:
You will be getting this log after the 'Authentication failed...'
Ensure that the following Android Key exists: ...
You can get correct SHA-1 key and package name below this 'Ensure that...' error message.
Both are separated by ';'
And now create new API key and add this new key in Manifest file tag.
**Manifest:**
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
This will solve your problem!

Related

Localization of cordova APP is not working

APP is in pause state. I am changing the language(localization) of the phone afterwards when I select the app from recent history(pause state to resume state). The following lifecycle methods are calling in following order
onDestroy
onCreate
onStart
onResume
onPause
onStop
onDestroy
but APP is not opening(view is not appearing).
Here I have given the source code of activity and android manifest file.
Any help is appreciated?
public class CordovaExample extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
Log.i("onCreate Called","onCreate Called");
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("OnStart Called","OnStart Called");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("onResume Called","onResume Called");
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("onPause Called","onPause Called "+Locale.getDefault().getLanguage());
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.i("onStop Called","onStop Called");
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("onDestroy Called","onDestroy Called");
}
}
manifestfile:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.apache.cordova.rest"
android:hardwareAccelerated="true"
android:versionCode="1"
android:versionName="1.0"
android:windowSoftInputMode="adjustPan" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="org.apache.cordova.rest.CordovaRestClient"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
</manifest>
Open the following Java File in cordova library project
framework/src/org/apache/cordova/CordovaWebView.java
Replace the following line of code
if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url))
to
if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)&& !url.equals("about:blank"))
It is working fine now

Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

I'm developing app in that i need show google map using Google Map V2.
I'm getting following error and automatically app stoped.
Unable to start activity ComponentInfo{com.example.getlocation/com.example.getlocation.Show}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
My Minsdk is 12.
Show.java
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;
public class Show extends Activity {
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 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();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
Show.xml
<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="com.example.getlocation.Show" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.getlocation"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.getlocation.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.getlocation.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="21" />
<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"
android:theme="#style/AppTheme" >
<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>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBCMyxIOHjpFyElj67osKbJwsZ8FrEN3Jg" />
<activity
android:name=".Show"
android:label="#string/title_activity_show" >
</activity>
</application>
</manifest>
I tried a lot but still getting same error...
Thanks in advance.

How to Display Map in Android?

I worked on Google Map and use Fragment not Fragmentactivity but not working . my code given below.
map.xml
**<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.google.android.gms.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>**
Map.java
public class Maps extends Fragment {
MapView m;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View v = inflater.inflate(R.layout.maps, container, false);
m = (MapView) v.findViewById(R.id.mapview);
m.onCreate(savedInstanceState);
return v;
}
#Override
public void onResume() {
super.onResume();
m.onResume();
}
#Override
public void onPause() {
super.onPause();
m.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
m.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
m.onLowMemory();
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tech.Conference"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<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.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.permission.MAPS_RECEIVE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.tech.Conference.SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.technostacks.Conference.MainActivity"
android:logo="#drawable/menu_icon"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
</activity>
</application>
</manifest>
this code but not success.
Gettin error like this..
java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
you have to add one more meta-data in your Manifest.xml
meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your key"
You have used mapv1 which is deprecated , use mapv2

Android Google Map classNotFound exception

Basically I am trying to make an app which displays a Google Map.Here is my code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="my key goes here"
/>
</LinearLayout>
MainActivity class...
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends MapActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
When I run it,I get the following message
06-22 15:54:03.622: E/AndroidRuntime(26187): FATAL EXCEPTION: main
06-22 15:54:03.622: E/AndroidRuntime(26187): java.lang.RuntimeException:
Unable to instantiate activity
ComponentInfo{com.example.maptutorial/com.example.maptutorial.MainActivity}:
java.lang.ClassNotFoundException: com.example.maptutorial.MainActivity
Perhaps I might be doing something wrong in my Manifest File,and can not see it..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.maptutorial.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>
</manifest>
you forgot to add uses-library in your manifest file,in this case
<application>
...
<uses-library android:name="com.google.android.maps"
android:required="true" />
...
</application>
I think you are using MAP API version 1 which is deprecated.
Why Cant you use API 2 either Fragment or support-fragment (https://developers.google.com/maps/documentation/android/start)
<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"/>
Manifest file
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC8qEhdHVd3ZtxCR0549UqwnM72h0jgoMY" />
Basically I had to use the use the SupportMapFragment like this to make it work for android 2.3 .Also had to create a new API key..
<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/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
And an sample of my java code is this.
public class EmergencyMap extends FragmentActivity {
static final LatLng ASTYNOMIA = new LatLng(39.620530, 22.401728);
static final LatLng PYROSVESTIKH = new LatLng(39.632652, 22.398704);
static final LatLng genikonosokomeio = new LatLng(39.642081, 22.422350);
static final LatLng panosokomeio = new LatLng(39.609993, 22.385722);
private GoogleMap map;
final int RQS_GooglePlayServices = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_emergency_map);
map = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions().position(ASTYNOMIA).title("ΑΣΤΥΝΟΜΙΑ"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(ASTYNOMIA,15));
map.animateCamera(CameraUpdateFactory.zoomTo(20),2000,null);
map.addMarker(new MarkerOptions().position(PYROSVESTIKH).title("ΠΥΡΟΣΒΕΣΤΙΚΗ"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(PYROSVESTIKH,15));
map.animateCamera(CameraUpdateFactory.zoomTo(20),2000,null);
map.addMarker(new MarkerOptions().position(genikonosokomeio).title("ΓΕΝΙΚΟ
ΝΟΣΟΚΟΜΕΙΟ"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(genikonosokomeio,15));
map.animateCamera(CameraUpdateFactory.zoomTo(20),2000,null);
map.addMarker(new MarkerOptions().position(panosokomeio).title("ΠΑΝΕΠΙΣΤΗΜΙΑΚΟ
ΝΟΣΟΚΟΜΕΙΟ"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(panosokomeio,15));
map.animateCamera(CameraUpdateFactory.zoomTo(20),2000,null);
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
protected void onResume() {
super.onResume();
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"Το κινητό σας υποστηρίζει GooglePlayServices",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this,RQS_GooglePlayServices);
}
}
}
It is Google Map API 2. Here is a part of my manifest file.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission
android:name="com.example.larissaguide.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="larissa.app.permission.MAPS_RECEIVE" />
<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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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="larissa.app.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="MY_KEY_GOES_HERE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />

Can´t run my app with google maps api v2

I tried everything, I researched and I can't get run my application. Each time I Run my application on my device get the message: "Sorry, Map has been has been interrupted". I done all the steps from this page https://developers.google.com/maps/documentation/android/start?hl=pl, and follow many tutorial and nothing. I hope you can save me.
Manifeste File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<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"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.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>
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBEGWDP9v4HepDF9A1NmSfFYjfdU2Jezm4" />
</application>
</manifest>
XML File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And my MainActivity:
package com.example.map;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
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();
} catch (Exception e) {
e.printStackTrace();
}
}
#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;
}
/**
* 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();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
Please Help me!!!!
try this :
class="com.google.android.gms.maps.SupportMapFragment"
on your activity :
SupportMapFragment mapfragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.showmap);
I think your problem in
android:name="com.google.android.gms.maps.MapFragment"
try instead of this, in the way:
class="com.google.android.gms.maps.MapFragment"
P.S. sometimes problem with maps is in not available Google Play Service on device.
(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS)
must be true.

Categories

Resources