Programming User
Programming User

Reputation: 11

Android application - using google maps

I'm new to android development and am looking for someone to help me integrate google maps with my application. Have been trying a few samples I found on the internet but can't seem to get it work. I need to connect google maps with my application and show a route, the same route that I need to create using google maps.

Any help will be really appreciated!

This is my activity_main.xml:

<?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.MapFragment"/>

The MainActivity looks like this:

public class MainActivity extends Activity {

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

And this is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

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

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="--------------------------------------" />

        <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>
        <activity android:name=".AboutUs" >
        </activity>
</application>
</manifest>

Log error:

09-06 08:55:31.325: I/dalvikvm(302): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView. 09-06 08:55:31.325: W/dalvikvm(302): VFY: unable to resolve virtual method 505: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable; 09-06 08:55:31.325: D/dalvikvm(302): VFY: replacing opcode 0x6e at 0x008b 09-06 08:55:31.325: I/dalvikvm(302): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView. 09-06 08:55:31.325: W/dalvikvm(302): VFY: unable to resolve virtual method 498: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable; 09-06 08:55:31.325: D/dalvikvm(302): VFY: replacing opcode 0x6e at 0x0099 09-06 08:55:31.345: D/dalvikvm(302): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;. (Landroid/content/Context;Landroid/util/AttributeSet;)V 09-06 08:55:31.345: D/dalvikvm(302): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;. (Landroid/content/Context;Landroid/util/AttributeSet;)V 09-06 08:55:31.525: W/dalvikvm(302): Unable to resolve superclass of Lcom/google/android/gms/maps/MapFragment; (30) 09-06 08:55:31.525: W/dalvikvm(302): Link of class 'Lcom/google/android/gms/maps/MapFragment;' failed 09-06 08:55:31.535: D/AndroidRuntime(302): Shutting down VM 09-06 08:55:31.535: W/dalvikvm(302): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 09-06 08:55:31.555: E/AndroidRuntime(302): FATAL EXCEPTION: main 09-06 08:55:31.555: E/AndroidRuntime(302): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.avpanelswalks/com.example.avpanelswalks.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.os.Handler.dispatchMessage(Handler.java:99) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.os.Looper.loop(Looper.java:123) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-06 08:55:31.555: E/AndroidRuntime(302): at java.lang.reflect.Method.invokeNative(Native Method) 09-06 08:55:31.555: E/AndroidRuntime(302): at java.lang.reflect.Method.invoke(Method.java:521) 09-06 08:55:31.555: E/AndroidRuntime(302): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-06 08:55:31.555: E/AndroidRuntime(302): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-06 08:55:31.555: E/AndroidRuntime(302): at dalvik.system.NativeStart.main(Native Method) 09-06 08:55:31.555: E/AndroidRuntime(302): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.inflate(LayoutInflater.java:385) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:128) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77) 09-06 08:55:31.555: E/AndroidRuntime(302): at com.example.avpanelswalks.MainActivity.onCreate(MainActivity.java:21) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 09-06 08:55:31.555: E/AndroidRuntime(302): ... 11 more 09-06 08:55:31.555: E/AndroidRuntime(302): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.avpanelswalks-1.apk] 09-06 08:55:31.555: E/AndroidRuntime(302): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 09-06 08:55:31.555: E/AndroidRuntime(302): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 09-06 08:55:31.555: E/AndroidRuntime(302): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.createView(LayoutInflater.java:466) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544) 09-06 08:55:31.555: E/AndroidRuntime(302): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 09-06 08:55:31.555: E/AndroidRuntime(302): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 09-06 08:55:31.555: E/AndroidRuntime(302): ... 19 more

Upvotes: 0

Views: 244

Answers (1)

Martin Golpashin
Martin Golpashin

Reputation: 1062

You won't find better instructions than the Google Documentation:

  1. Get an API Key for Google Maps
  2. Add a map to your Application
  3. Use the Google Directions API to request the routes you need

More information https://developer.android.com/google/play-services/maps.html

Update: Try using a SupportMapFragment (com.google.android.gms.maps.SupportMapFragment) instead of com.google.android.gms.maps.MapFragment in your layout.xml. You also need to extend FragmentActivity then instead of Activity

Upvotes: 1

Related Questions