Android Google Map classNotFound exception - android

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" />

Related

Maps v2 android

I have made a simple google map in android but the problem is that on running i m only gettin zoom buttons and map is not loading.I have generated api key 3 time.
here is manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amal.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<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"/>
<!-- The following two permissions are required for location -->
<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.amal.googlemap.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="AIzaSyCh4vRdbH__Dgg7n-3t8TTkhsUVC8CtNKM"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
here is xml file
`
<?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.SupportMapFragment"/>`
here is class file
public class MainActivity extends Activity {
GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
LatLng latLng = new LatLng(13.05241, 80.25082);
map.addMarker(new MarkerOptions().position(latLng).title("Raj Amal"));
}}
Plz if anyone can help
Update
First of all check that you have googleplayservice library added in your project, Then
Use FragmentActivity. Activity is not from v4 nor from v7 support libraries. This should work:
public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
in onCreate
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);
googleMap = fm.getMap();
}

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.

Android application not showing my location in map, error: could not find 'com.google.android.gms.location.internal.parceablegeofence'

My android application is not showing my location on the map, but everything else is working fine and I have tried all the other solutions from other posts and google.
The locate button is showing but nothing happens when I click it and I don't know how to get the exception.
This is my code:
public class MainActivity extends FragmentActivity {
private GoogleMap myMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
initilizeMap();
myMap.setMyLocationEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (myMap == null) {
myMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (myMap == null) {
Toast.makeText(getApplicationContext(),"Map not created", Toast.LENGTH_SHORT).show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
This is my androidmanifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.none"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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="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" />
<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"/>
<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.maps.v2.API_KEY"
android:value="HIDDEN" />
</application>
</manifest>
This is my activity main xml:
<?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"
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="com.example.none.MainActivity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Seleccione el punto clave" />
</RelativeLayout>
This is what logcat shows me:
Could not find 'gpq', referenced from method gpr.a
Could not find 'ovw', referenced from method oyf.a
Could not fin class 'com.google.android.gms.location.internal.parceablegeofence', referenced from method gls.a
I have solved it! just needed to implement a LocationListener to the MainActivity and its methods. Tell me if you need some code as answer.

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

Google Map view shows only grey screen with zoom button

I am Using android Google map API-2 for my application. When clicking map view it shows only a screen with zoom button.
my AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.burusoth.advertise"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.burusoth.advertise.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.burusoth.advertise.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<!-- 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.burusoth.advertise.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>
<activity
android:name="com.burusoth.advertise.View_Advertisements"
android:label="#string/title_activity_view__advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Gadget_view"
android:label="#string/title_activity_gadget_view"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.burusoth.advertise.Activity_post_advertisements"
android:label="#string/title_activity_activity_post_advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Post_Advertisement"
android:label="#string/title_activity_post__advertisement" >
</activity>
<activity
android:name="com.burusoth.advertise.Popup"
android:label="#string/title_activity_popup" >
</activity>
<activity
android:name="com.burusoth.advertise.Google_Map"
android:label="#string/title_activity_google__map" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAKCvpyR3v4YStDJDoibNgoblkdch0F254" />
</application>
my activity xml file
<RelativeLayoutxmlns: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=".Google_Map" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
my Activity .java Activity file for calling map
public class Google_Map extends Activity {
private GoogleMap googleMap=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google__map);
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.activity_google__map, menu);
return true;
}
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();
}
}
Here with I would like to share one example which run under Google Map API v2.
You can go through that steps or else you can download full example from below link.
This is working example. Please test this in real device.
Google Maps API v2 using Android
Please provide your comment if you have any question.
You need to put API_KEY in android manifest
Get from :
Google Map API_KEY

Categories

Resources