1. Download our Official Android App: Forums for Android!

Apps Need Some Help "Google Maps Activity"

Discussion in 'Android Development' started by ac4android, Feb 25, 2016.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    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 (Text):
    1.  
    2.     // LISTEN to what the user wants... following is what happens if the user clicks on it
    3.     @Override
    4.     public void onListItemClick(ListView listDeliveriestView,
    5.                                 View itemView,
    6.                                 int position,
    7.                                 long id) {
    8.         Intent intent = new Intent(ListDeliveriesActivity.this, ShowMapActivity.class);
    9.         intent.putExtra(ListDeliveriesActivity.EXTRA_LISTNO, (int) id);   // using a constant  makes it easier to retrieve to "send" the data
    10.         startActivity(intent);
    11.  

    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 (Text):
    1.  
    2. import android.app.Activity;
    3. import android.app.AlertDialog;
    4. import android.content.DialogInterface;
    5. import android.content.Intent;
    6. import android.content.pm.PackageInfo;
    7. import android.content.pm.PackageManager;
    8. import android.net.Uri;
    9. import android.os.Bundle;
    10.  
    11. public class ShowMapActivity extends Activity {
    12.  
    13.     protected void showMap(){
    14.  
    15.         // hardcoded for testing purposes, the latitude and longitude comes from another activity  
    16.         boolean installedMaps = false;
    17.         double FROM_LATITUDE = 36.778261;
    18.         double FROM_LONGITUDE = -119.417932;
    19.         String siteName = "Somewhere in LA";
    20.  
    21.         // Check whether GGoogle Maps is installed
    22.         PackageManager pkMgr = getPackageManager();
    23.         try{
    24.             @SuppressWarnings("unused")
    25.             PackageInfo pkInfo = pkMgr.getPackageInfo("com.google.android.apps.maps", 0);
    26.             installedMaps = true;
    27.         } catch(Exception e) {
    28.             e.printStackTrace();
    29.             installedMaps = false;
    30.         }
    31.         //Show the map using the co-ordinates from the checkin
    32.         if (installedMaps == true){
    33.             String geoCode = "geo:0,0?q="
    34.                     + SITE_LATITUDE + ", "
    35.                     + SITE_LONGITUDE
    36.                     + "(" + siteName + ")";
    37.             Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
    38.                     Uri.parse(geoCode));
    39.             startActivity(sendLocationToMap);
    40.         } else if (installedMaps == false) {
    41.             AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ShowMapActivity.this);
    42.             // Set the icon, replace the ic_launcher.png with something more meaningful
    43.             alertDialogBuilder.setIcon(R.mipmap.ic_launcher);
    44.             // Set the Title
    45.             alertDialogBuilder.setTitle("Maps not found!");
    46.  
    47.             // Set the message
    48.             alertDialogBuilder
    49.                     .setMessage(R.string.noMapsInstalled)    // <=== create an entry in values/string e.g. <string name="noMapsInstalled">No Map Installed</string>
    50.                     .setCancelable(false)
    51.                     .setNegativeButton("Got it.",
    52.                             new DialogInterface.OnClickListener(){
    53.                                 public void onClick(DialogInterface dialog, int id){
    54.                                     dialog.dismiss();
    55.                                 }
    56.                             });
    57.  
    58.                            
    59.             // Create, then show the alert dialog
    60.             AlertDialog alertDialog = alertDialogBuilder.create();
    61.             alertDialog.show();
    62.         }
    63.     }
    64. }
    65.  
    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?
     

    Advertisement

  2. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Have you enabled the google libs with this? I had the same issue when I started to use GCM.
    You have all of the google dependencies in your Gradle file?
     
  3. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    Sorry but I am a but of a neophyte when it comes to Google Maps.

    How do I find out whether I've all the Google dependencies in the Gradle?
     
  4. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    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

    Code (Java):
    1. // Top-level build file where you can add configuration options common to all sub-projects/modules.
    2.  
    3. buildscript {
    4.     repositories {
    5.         jcenter()
    6.     }
    7.     dependencies {
    8.         classpath 'com.android.tools.build:gradle:1.5.0'
    9.        
    10.  
    11.         // NOTE: Do not place your application dependencies here; they belong
    12.         // in the individual module build.gradle files
    13.     }
    14. }
    15.  
    16. allprojects {
    17.     repositories {
    18.         jcenter()
    19.     }
    20. }
    21.  
    22. task clean(type: Delete) {
    23.     delete rootProject.buildDir
    24. }
    25.  
    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

    Code (Java):
    1. apply plugin: 'com.android.application'
    2.  
    3. android {
    4.     compileSdkVersion 23
    5.     buildToolsVersion "23.0.2"
    6.  
    7.     defaultConfig {
    8.         applicationId "com.example.mmillar.loginpage"
    9.         minSdkVersion 8
    10.         targetSdkVersion 23
    11.         versionCode 1
    12.         versionName "1.0"
    13.     }
    14.     buildTypes {
    15.         release {
    16.             minifyEnabled false
    17.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    18.         }
    19.     }
    20. }
    21.  
    22. dependencies {
    23.     compile fileTree(dir: 'libs', include: ['*.jar'])
    24.     testCompile 'junit:junit:4.12'
    25.     compile 'com.android.support:appcompat-v7:23.2.0'
    26.     compile 'com.android.support:design:23.2.0'
    27.  
    28. }
    29.  

    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.
     
  5. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    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.
     
    #5 ac4android, Feb 28, 2016
    Last edited: Feb 29, 2016
  6. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    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
     

Share This Page

Loading...