Amy Lee
Amy Lee

Reputation: 11

Google map doesn't appear in my android application

the map doesn't appear in my app and I can't figure out what's the problem at my code I've tried my best to resolve this problem, hope u could help me to resolve this ,here's the main layout :

     <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1"
    android:background="#fffffbec"
    android:id="@+id/heady">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="127dp"
        android:layout_gravity="top"
        android:layout_weight="0.86"
        android:weightSum="1"
        android:id="@+id/bodylay"
        android:gravity="bottom">
        <LinearLayout android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:id="@+id/acquiring_signal_layout"
            android:background="#fff8edff"
            android:gravity="center_vertical">
            <ProgressBar
                android:id="@+id/ProgressBar01"
                style="@color/green"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/acquiring_signal_label"
                android:layout_width="275dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:paddingLeft="5dp"
                android:text="@string/acquiring_signal"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#ff12bec1" />
        </LinearLayout>
        <com.google.android.maps.MapView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/MapView"
            android:layout_width="match_parent"
            android:layout_height="274dp"
            android:apiKey="0oR0G95fEqsQy8FGrgFXeZ4U3NnHNmRZUbPh_8A"
            android:clickable="true"
            android:layout_weight="0.81" />
    </LinearLayout>
    <Button
        android:id="@+id/SendButton"
        android:layout_width="238dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="@string/send_button"
        android:visibility="visible"
        android:layout_gravity="center"
        android:background="#ff12bec1"
        android:layout_weight="0.11"
        android:textColor="#fffefff3" />
</LinearLayout>

and this is the mainfest :

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"
    package="com.mylocation.hanan.mylocation" >
    <uses-sdk android:targetSdkVersion="13" android:minSdkVersion="9"></uses-sdk>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
    <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-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault.NoActionBar" >
        <!--@style/AppTheme-->
     <uses-library android:required="true" android:name="com.google.android.maps"></uses-library>

        <activity
            android:name="com.mylocation.hanan.mylocation.Sharelocation"
            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.mylocation.hanan.mylocation.Preferences"
            android:label="@string/preferences_activity">
            <intent-filter>
                <action android:name="com.mylocation.hanan.mylocation.action.Preferences" />
            </intent-filter>
        </activity>


    </application>

</manifest>

Upvotes: 1

Views: 2118

Answers (1)

Prokash Sarkar
Prokash Sarkar

Reputation: 11873

Points to be noted:

1. You are using an older version of Google Map which is no longer supported.

2. You might be using the wrong API keys.

3. You haven't added the proper permissions on the manifest file.

4. Make sure you have included the Google Play Services library to your project.

Possible solutions,

A. Add a support map fragment in your xml,

<fragment 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:id="@+id/map"
    tools:context=".MapsActivity"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

B. Use the support map fragment in your activity and implement onMapReadyCallback

public class MapPane extends Activity implements OnMapReadyCallback {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_activity);

        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        LatLng sydney = new LatLng(-33.867, 151.206);

        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
    }
}

Source:

Google Maps Android API

C. Add proper permissions on the manifest file,

    <!-- Creating Permission to receive Google Maps -->
    <permission
        android:name="com.example.app.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <!-- Permission to receive Google Maps -->
    <uses-permission android:name="com.example.app.permission.MAPS_RECEIVE" />

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

D. To get a Google Maps API key follow the instructions here,

Get a Google Maps API key

Upvotes: 1

Related Questions