开发者

Map Demo application in Android not working properly

开发者 https://www.devze.com 2023-02-10 20:04 出处:网络
I am trying my first map application in Android but when I run the application, a message in the emulator is displayed saying

I am trying my first map application in Android but when I run the application, a message in the emulator is displayed saying

"the application APPLICATION NAME stopped unexpectedly"

Here is the code:

demomaps.java

    package com.tutorial.demomaps;

//import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.android.maps.*;

public class demomaps extends MapActivity {
    /** Called when the activity is first created. */
    LinearLayout linearLayout;
    MapView mapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapView = (MapView)findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        setContentView(R.layout.main);
    }

    @Override
    protected boolean isRouteDisplayed()
    {

        return false;
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="00OHG4fs5JkMMURfVtKse-D3wVv1BImlK_3zz3g">   

</com.google.android.maps.MapView>
</RelativeLayout>   

AndroidManifest.xml

<?xml version="1.0" encoding="开发者_如何学Pythonutf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tutorial.demomaps"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".demomaps"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps"></uses-library>
    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>


Sid,

Code looks ok to me. Make sure emulator is using the Google API's. If not, create new emulator that does for testing.


I got the application running, first I got the the Key form Google again and placed it in main.xml (again) and I added permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>

along with android.permission.INTERNET to the AndroidManifest.xml and built the project and ran it. This worked in my case, might help other people who get the same issue.

Thanks, Sid

0

精彩评论

暂无评论...
验证码 换一张
取 消