• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need Some Help "Google Maps Activity"

ac4android

Well-Known Member
Nov 3, 2015
198
29
Hi,

My app cascades through several activities at the end of which it should display a Google Map with the "From" and "To" points.

Everything works fine until the app tried to execute the intent to display the map, this is the code-snippet that creates the Intent, then starts the activity:
Code:
    // LISTEN to what the user wants... following is what happens if the user clicks on it
    @Override
    public void onListItemClick(ListView listDeliveriestView,
                                View itemView,
                                int position,
                                long id) {
        Intent intent = new Intent(ListDeliveriesActivity.this, ShowMapActivity.class);
        intent.putExtra(ListDeliveriesActivity.EXTRA_LISTNO, (int) id);   // using a constant  makes it easier to retrieve to "send" the data
        startActivity(intent);


Following is the Java code, I mostly copied from developer.android.com/guide and stackoverflow, but haven't been able to get that working:
Code:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;

public class ShowMapActivity extends Activity {

    protected void showMap(){

        // hardcoded for testing purposes, the latitude and longitude comes from another activity   
        boolean installedMaps = false;
        double FROM_LATITUDE = 36.778261;
        double FROM_LONGITUDE = -119.417932;
        String siteName = "Somewhere in LA";

        // Check whether GGoogle Maps is installed
        PackageManager pkMgr = getPackageManager();
        try{
            @SuppressWarnings("unused")
            PackageInfo pkInfo = pkMgr.getPackageInfo("com.google.android.apps.maps", 0);
            installedMaps = true;
        } catch(Exception e) {
            e.printStackTrace();
            installedMaps = false;
        }
        //Show the map using the co-ordinates from the checkin
        if (installedMaps == true){
            String geoCode = "geo:0,0?q="
                    + SITE_LATITUDE + ", "
                    + SITE_LONGITUDE
                    + "(" + siteName + ")";
            Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(geoCode));
            startActivity(sendLocationToMap);
        } else if (installedMaps == false) {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ShowMapActivity.this);
            // Set the icon, replace the ic_launcher.png with something more meaningful
            alertDialogBuilder.setIcon(R.mipmap.ic_launcher);
            // Set the Title
            alertDialogBuilder.setTitle("Maps not found!");

            // Set the message
            alertDialogBuilder
                    .setMessage(R.string.noMapsInstalled)    // <=== create an entry in values/string e.g. <string name="noMapsInstalled">No Map Installed</string>
                    .setCancelable(false)
                    .setNegativeButton("Got it.",
                            new DialogInterface.OnClickListener(){
                                public void onClick(DialogInterface dialog, int id){
                                    dialog.dismiss();
                                }
                            });

                           
            // Create, then show the alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }
}
The error message:
02-26 00:04:59.990 281-377/system_process E/ThrottleService: problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)


QUESTION 1: I do not understand that, what file or directory is Android looking for?

QUESTION 2: Do I need the XML for displaying the map? If so, are there sample codes out there how to set up an XML for maps?

QUESTION 3: How can I coax Android to display amap with the "From" and the "To" points?
 
Try here this is where I went to get the google cloud messaging stuff set up but this one is for the maps
https://developers.google.com/maps/documentation/android-api/utility/setup
It will go step by step to show you how to set up your working environment.

For the gradle you go into your
GradleScripts > buildGradle(project scritps)
That is where you will find the place to put in your dependencies.
if will look like this

Java:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
       

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Then there is another build file that you may have to edit its called the same as the other but this is where you put the other dependencies and will look like this

Java:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.mmillar.loginpage"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'

}


Here is where I first messed up:
If you look at the first one it has in the dependency section "classpath" i.e. classpath' somewhere.in.the.world.service-thingy
This is where you put the classpath items you need for the google-services:
For example I placed
classpath 'com.google.gms:google-services:1.5.0-beta2'
in this location for Google Cloud Messaging.

In the other file is where you place the plugins and the compile services like this
compile "com.google.android.gms:play-services:8.4.0"

and at the bottom NOT the top (it wont work otherwise 1st hand experience) you place the plugins like:
apply plugin: 'com.google.gms.google-services'


I hope that this was a clear explanation of what you asked.
 
Upvote 0
Thanks :)

This one is the clincher:
compile "com.google.android.gms:play-services:8.4.0"

I tried earlier versions based on what I am reading on the web, e.g. 4.+, and up-ed the version until it worked.

Also, I needed the Google API key, I got that through my Google account, which I had to embed in my res/values/google_maps_api.xml

I found that once I've created an AVD ( I named it "Nexus 4 API21")<s> , the key will only work with that AVD and no others.</s> I tried running it on an earlier Android version, won't work, but will work on more recent release e,g, API22

In the meantime, the response time has slowed significantly, will have to load that on my Android ( the real one ) for faster performance.

QUESTION: did you have to get a new Google API key for each AVD as well?

QUESTION: Did you use "Google Maps Activity" instead of a black fragment? I am looking forward to the time when I have to use another map service provider other than Google.
 
Last edited:
Upvote 0
Sorry for the late response I am moving to Japan for work so its been kinda crappy for me. But from my experience you can enable multiple keys when you set up you services to use google. For instance with a GCM you can do both the push notification and maps with the same one. There should be an option where you can enable it when you get the google service json file
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones