Skip to content Skip to sidebar Skip to footer

Using Google Maps In Android

Trying to execute a MAP-API program in android MainActivity.java public class MainActivity extends FragmentActivity { // Google Map private GoogleMap googleMap; @Over

Solution 1:

Map V2:enter image description hereHere check your layout you are using MapFragment & SupportMapFragment so you are getting error Dont Use android:name="com.google.android.gms.maps.MapFragment"

Only Use

class="com.google.android.gms.maps.SupportMapFragment"

In Manifest: change the package name to yours

<activity
            android:name="com.example.mapearth.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppBaseTheme" >

Select The google play library

Solution 2:

Your package name is

package="com.example.mapearth"

But in activity declaration you have

  <activity
        android:name="info.androidhive.googlemapsv2.MainActivity"

CHange to

  <activity
        android:name="com.example.mapearth.MainActivity"

For api 12 and above use MapFragment else use SupportMapFragment.

If you are using MapFramgent you need to extend standard Activity and use getFragmentManager

Change your min sdk to 11 or below

You can also remove these

<permissionandroid:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"android:protectionLevel="signature" /><uses-permissionandroid:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />

Check out specifying permissions

https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2

Also remove the below from your xml

  android:name="com.google.android.gms.maps.MapFragment"// in case your min sdk is 11 and below use SupportMapFragment 

Edit:

In xml you have

    android:name="com.google.android.gms.maps.MapFragment"

In activity while initializing you have

googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

So change to

    android:name="com.google.android.gms.maps.SupportMapFragment"

and this

    <uses-sdk
    android:minSdkVersion="11"// 11 or below

Edit:

Refer to the google play services library project properly

Importing google-play-service library showing a red X next to this reference android

Solution 3:

try to replace your activity_main.xml file's content by it:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/main"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><fragmentxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment" /></LinearLayout>

Solution 4:

You need to use the SupportMapFragment in your activity_main.xml like so:

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

The activity is interpreting your XML as a SupportMapFragment however in your XML layout you state it is a normal Map Fragment, causing the error. Change it into a SupportMapFragment and it should interpret it correctly.

Post a Comment for "Using Google Maps In Android"