Map does not load, showing error

Asked

Viewed 1,154 times

2

I’m starting to develop on Android, only I came across a problem to generate a simple map, I’ve seen and reviewed the documentation of Google Developer and other internet tutorials that show how easy it is to make an application of this type. My code:

Androidmanifest file:

`

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<permission android:name="br.com.engandtec.locationmaps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="br.com.engandtec.locationmaps.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"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- 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" >

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyD-FWEwQsLHfJJWIyQc-TxALIGju-iMgvU"/>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"
         />  

    <activity
        android:name="br.com.engandtec.locationmaps.MapActivity"
        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>

`

file: activity_map

<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=".MapActivity" >

<TextView
    android:id="@+id/header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

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

and the file: Mapactivity

package br.com.engandtec.locationmaps;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MapActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.map, menu);
        return true;
    }

}

when I prompt aap to trim the following screen

and when you click the update button appears message that the app has stopped and Logcat shows these lines inserir a descrição da imagem aqui

  • You could inform the tutorial link and show us the error in text instead of image form?

  • @Math: The OS has reduced the image size to fit in the layout but you can download the image separately and it will be in normal size, with visible text.

  • @Piovezan I know, but it wouldn’t be easier if it was in text?

  • You tried running on a real device instead of emulator?

5 answers

1

You won’t be able to use the map in the Android emulator unless you go through a complex emulator modification process (which isn’t worth it).

The best thing to do is to use a third-party emulator. I use Genymotion.

In addition, it climbs and runs infinitely faster than the standard Android emulator.

Other information here.

0

Try these changes. You have to instantiate the map.

    public class MapActivity extends FragmentActivity {

        private GoogleMap mMap;

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

        @Override
        protected void onResume() {
            super.onResume();
            setUpMapIfNeeded();
        }

        private void setUpMapIfNeeded() {
            if (mMap == null) {
                mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
                if (mMap != null) {
                    setUpMap();
                }
            }
        }

        private void setUpMap() {
            mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.map, menu);
            return true;
        }
    }

0

This Exception probably means you don’t have the app Google Play Services installed. Download it from Google Play (using the app Play Store), run your project again and see if the error goes away.

  • Is it possible to download Google Play from the Play Store? I really don’t know, I’m curious.

  • @Math: In this case I refer to the Google Play Services app. I think you’re referring to the Play Store app, right? I never tried to download it, because it already comes installed on Android as far as I know.

  • 1

    @Complementing Math, here it is claimed that it cannot be lowered.

  • Yes, I was referring to the app. Whatever, can you download the services then? Maybe his solution is just to click on that update button, rs..

  • @Math: Clicking the update button causes the Exception. :)

  • Oh yeah! I need to read calmly, rs..

Show 1 more comment

0

You are in trouble when it comes to creating your Intent, because the error you posted is that there is no Activity that is responding for your Intent, this has nothing to do with Maps.

0

When you download sdk, Google Play services is there.

You can check if it is installed by clicking on the Android SDK Manager button (that button that sits on the bar that has an Android with an arrow down).

Once you open the SDK Manager, go to Extras and check that Google Play Services is installed. If not, check and click Install 1 package.

After you install, import the Google Play services library to your eclipse.
Import > Android > Existing Android Code Into Workspace > Root Directory (Browse) > Navigate where you installed android-sdks > extras > google > google_play_services > libproject > google-play-services_lib > Click open.

After that, go to your project, click with second button and then Properties > Android > Library > Add > and select from google_play_services.

Give a Clean and Build and should work.

  • google_play_services is already downloaded and tbm is in the project lib!

  • Okay, so take a look at the samples that exist in the same folder that contains that lib. But already beforehand. Since you are using a Fragment, it would be better to use a Fragmentactivity.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.