0

I wanted to begin writing a route tracking activity for the following xml

   <?xml version="1.0" encoding="utf-8"?>
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/mainLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ToggleButton
        android:id="@+id/trackingToggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:textOff="Start Tracking"
        android:textOn="Stop Tracking"/>
</FrameLayout>

and wrote the following in my NeueRouteAufzeichnen.java

package com.noureddine_ouertani.www.wocelli50;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import java.util.Map;
import com.google.android.maps.MapActivity;

public class NeueRouteAufzeichnen extends MapActivity {
}

maps is red in the following import

import com.google.android.maps.MapActivity;

and MapActivity as well in

public class NeueRouteAufzeichnen extends MapActivity 

although Google APIs (API 23) are installed. (I checked in Android SDK Manager) Am I trying to use something deprecated? Thanks in advance for any hints or help

PS: This is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.noureddine_ouertani.www.wocelli50"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-annotations:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.google.android.gms:play-services:9.0.2'
    compile 'com.google.android.gms:play-services-maps:9.0.2'
    compile 'com.google.android.gms:play-services-location:9.0.2'
    compile 'com.google.android.gms:play-services-base:9.0.2'
}

and I added the following in my AndroidManifest.xml

<uses-library android:name="com.google.android.maps"/>

EDIT: I changed my XML (activity_neue_route_aufzeichnen.xml) to this:

<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=".NeueRouteAufzeichnen"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

added this to my AndroidManifest.xml

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

after deleting this from it

 <uses-library android:name="com.google.android.maps"/>

and took the following class as a basis to build on when implementing my route tracking logic.

package com.noureddine_ouertani.www.wocelli50;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;


    public class NeueRouteAufzeichnen extends FragmentActivity implements OnMapReadyCallback {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_neue_route_aufzeichnen);
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
        }

        @Override
        public void onMapReady(GoogleMap map) {
            // Add a marker in Sydney, Australia, and move the camera.
            LatLng sydney = new LatLng(-34, 151);
            map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
            map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
        }
    }

I already tested this new activity that uses Google maps on my smartphone and it works. Now I can focus on tracking routes. I´ll publish my route tracking code here as soon as it works to apologize for this question. :)

PS: I had already added the map key I got from Google to my strings.xml in the values folder. Thanks to all of you for your answers. Lesson of the day: MapActivity is out! FragmentActivity is in!

EDIT2: This thread is not a duplicate anymore after EDIT from my point of view because I explained how to integrate your first Google Maps activity in your Android project through describing what I did. Furthermore I´ll post my route tracking logic here.

0 Answers0