1

I'm trying to display a map inside an activity in an app, keep in mind that I'm using Android Studio 0.3.1; switching to Eclipse is not an option unless doing so in Android Studio is absolutely impossible.

I've followed multiple tutorials on how to do it, the most recent ones being a second attempt at the Google Developers one and Vogella's one, as well as similar questions such as, but not limited to, this and this; All to no avail, following the mentioned tutorials only give me a crash at runtime with the following message:

E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptestproject/com.example.maptestproject.MainActivity}: android.view.InflateException: Binary XML file line #69: Error inflating class fragment

Quite naturally, also tried to check the sample found in the Google Play API, but I cannot run it in Android Studio as it either gives me a "output path not specified" error if it has the Make option before launch or an "APK path is not specified" if I remove it (as suggested in couple places).

Currently, my test project is as follows, MY_API_KEY is replaced by my actual API key in the actual project:

Manifest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.maptestproject"
        android:versionCode="1"
        android:versionName="1.0" >
        <uses-sdk
            android:minSdkVersion="17"
            android:targetSdkVersion="17" />
        <permission
            android:name="com.example.maptestproject.maps.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />

        <permission
    android:protectionLevel="signature" />
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/>
        <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"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.maptestproject.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>
            <meta-data
                android:name="com.google.android.maps.v2.MY_API_KEY"
                android:value="MY_API_KEY"/>
        </application>
    </manifest>

MainActivity.java:

    package com.example.maptestproject;
    import android.support.v4.app.FragmentActivity;
    import android.os.Bundle;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MainActivity extends FragmentActivity {
        static final LatLng HAMBURG = new LatLng(53.558, 9.927);
        static final LatLng KIEL = new LatLng(53.551, 9.993);
        private GoogleMap map;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG).title("Hamburg"));
            Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

            map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
            }
    }

activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context=".MainActivity" >

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

    </RelativeLayout>

To be a bit more specific, the app needs to show a specific location and then trace a path from the user's current location to the marked location (or send to a webview with google maps, or open the device's gps, whatever is more straightforward), but any inputs in just making the thing work will be greatly appreciated.

I apologize for the very long question, but this is something that's been giving me trouble for nearly 2 days now.

Community
  • 1
  • 1
Larpus
  • 301
  • 1
  • 3
  • 17

0 Answers0