Help with hello world MapQuest app in Android Studio

28 posts / 0 new
Last post
hermesuruguay
Help with hello world MapQuest app in Android Studio

Hello everyone,

I'm trying to build a very simple app in android which only displays a MapQuest map. And nothing else.

I followed this tutorial https://developer.mapquest.com/documentation/android-sdk/ but it does not seem to work.

It says that the imports:

import com.mapquest.mapping.maps.OnMapReadyCallback;
import com.mapquest.mapping.maps.MapboxMap;
import com.mapquest.mapping.maps.MapView;

       cannot be resolved.

What can it be?

Everything in my project is exactly as the tutorial states.

Thanks in advance.

Best regards.

Federico.


MQBrianCoakley
Make sure all of the steps
Make sure all of the steps before coding are working successfully. It sounds like the libraries are not being found in the build causing the imports to fail.

hermesuruguay
Thanks Brian. It seems that

Thanks Brian. It seems that my Android Studio is not getting to "download" this "maven { url 'http://artifactory.cloud.mapquest.com/artifactory/et-android-binaries' }" in the build.gradle.

I made another project and included the mapquest JAR to the library and it is working.

But it seems to be an old library (1.0.5), now it is something like 1.3.2 I think.

Why can it be that maven does not get to that repo? Everything else is working fine, the steps are followd exactly as stated. Does that tutorial work for you?

Thanks a lot for your time and effort. Much appreciated.

Best,

    Federico.


MQBrianCoakley
I'm not sure why the url
I'm not sure why the url would not work in one project then work in another.   The 1.0.5 version should work but the documentation will get updated to the latest version, 1.3.2, in the near future.   It's been a while, but yes, the tutorial has always worked great for me. I've started numerous projects following those steps.

hermesuruguay
Will keep trying

Ok. Will keep trying.

If it is not to much trouble, can you share a blank project that only shows a mapquest map? Maybe with the basic map working with 1.3.2.

It is OK if you cannot do that, i will understand.

Thanks again for all your help, obviusly i'm doing something wrong!

Best regards,

    Federico.


hermesuruguay
New error

I kept trying and think some progress was made.

Now the library is imported, but the project cannot run.

This is the error: Caused by: java.lang.UnsatisfiedLinkError: Couldn't load mapbox-gl from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/hermes.com.uy.mapquest_v3-1.apk"],nativeLibraryDirectories=[/data/app-lib/hermes.com.uy.mapquest_v3-1, /vendor/lib, /system/lib]]]: findLibrary returned null.

I've seen it happened to some people, but could not found a solution to it.

Have you seen it?

Any help is more than wellcome.

Best regards,

    Federico.


MQBrianCoakley
Are you setting the key in
Are you setting the key in activity_main.xml?

hermesuruguay
activity_main.xml

Yes, this is the text of 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="hermes.com.uy.zfbffs.MainActivity">

<com.mapquest.mapping.maps.MapView
android:id="@+id/mapquestMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapquest_app_key="KEY"
/>
</RelativeLayout>


hermesuruguay
Ideas

Thanks for editing the Key Brian. Any ideas to try?

Best, Federico.


MQBrianCoakley
The development team is
The development team is working on updating the documentation to address this issue. I hope to see this update go live next week. Sorry for the confusion.

ckuether
Similar issue

I seem to be having a similar issue setting up the hello_world application.

Caused by: java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.example.corey.mapquest_location/files/instant-run/dex/slice-support-annotations-25.1.0_e93dd9f31ed44f1ad1bec9f07f321447d78f1734-classes.dex",

Is this issue ongoing?


MQBrianCoakley
Yes. The update to the
Yes. The update to the documentation should go live later this week.

MQBrianCoakley
The update to the
The update to the documentation is getting pushed out a week. I have the udpated information and it worked great in a quick project I threw together.   The current version is 1.3.2 so your include url in the app build.gradle file should look like    com.mapquest:mapping-android-sdk:1.3.2@aar  In the MainActivity add the following after the super.onCreate call.   MapboxAccountManager.start(getApplicationContext());  You'll need to import the MapboxAccountManager.   You should/can also add the following overrides in the MainActivity.   public void onResume() { super.onResume(); mMapView.onResume(); } @Override public void onPause() { super.onPause(); mMapView.onPause(); } @Override protected void onDestroy() { super.onDestroy(); mMapView.onDestroy(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); }  This should get you up and running.

hermesuruguay
Thanks Brian, now it is

Thanks Brian, now it is working. But with some flaws I think. 1) Does ti require a MinSDKVersion? I was working with API15 and did not run, it does with API24 (only tried those two). 2) There is a constant message in LogCat saying "E/emuglGLESv2_enc: a vertex attribute index out of boundary is detected. Skipping corresponding vertex attribute.", it this normal? Will try the rest of the examples of the documentation and let you know. Thanks again. Federico.


hermesuruguay
All examples work but 'Use the User Location'

Brian, all examples work great except for "Use the User's Location". There is one correction to be made and one problem I could not solve:

Correction) "ActivityCompat.checkSelfPermission(this, Manifest.permission.XXX)" should be changed to "this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)". This is done two times in the method "enableUserTracking".

Problem) "mapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW)" says that "setMyLocation is not public. Cannot be accessed from outside the package."

I know that the documentation is currently under construction, but maybe this helps! And if I can help in any other way please let me know.

Thanks again, Federico.


hermesuruguay
Any news?

Hello Brian, any news in this matter?

Mostly for the 'Use the user location' functionality.

Thanks again! Federico.


MQBrianCoakley
Yes, there is an update to
Yes, there is an update to both mobile mapping sdks coming that is expected later this month and those will include updates to the documentation. This is how I got the user location to show up on the map.     import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.mapbox.mapboxsdk.MapboxAccountManager; import com.mapquest.mapping.maps.MapView; import com.mapquest.mapping.maps.MapboxMap; import com.mapquest.mapping.maps.OnMapReadyCallback; public class MainActivity extends AppCompatActivity { private MapboxMap mMapboxMap; private MapView mMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapboxAccountManager.start(getApplicationContext()); setContentView(R.layout.activity_main); mMapView = (MapView) findViewById(R.id.mapquestMapView); mMapView.onCreate(savedInstanceState); mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapboxMap mapboxMap) { mMapboxMap = mapboxMap; mMapboxMap.setMyLocationEnabled(true); } }); } }

hermesuruguay
Still no luck.

Thanks Brian. That code has no efect in my app. Nothing displayed over my location, the gps icon does not appear in the android topbar, and also no button to go to my location appears in map.

Here is a sceen shot: https://www.dropbox.com/s/ierfqypbm4sbnmp/Screenshot_20170210-160815.png...

And at the bottom all my code, including your last suggestion.

Thanks again.

Best, Federico.

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;

import com.mapbox.mapboxsdk.MapboxAccountManager;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapquest.mapping.constants.Style;
import com.mapquest.mapping.maps.MapView;
import com.mapquest.mapping.maps.MapboxMap;
import com.mapquest.mapping.maps.OnMapReadyCallback;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

private MapView mMapView;
private MapboxMap mMapboxMap;

private final LatLng NY = new LatLng(-34.5326808, -56.5843407);

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

mMapView = (MapView) findViewById(R.id.mapquestMapView);

mMapView.onCreate(savedInstanceState);

mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mMapboxMap.setMyLocationEnabled(true);
}
});
}

private void addMarker(MapboxMap mapboxMap) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(NY);
markerOptions.title("New York");
markerOptions.snippet("Welcome to New York!");
mapboxMap.addMarker(markerOptions);
}

private void setPoyline(MapboxMap mapboxMap) {
List<LatLng> coordinates = new ArrayList<>();
coordinates.add(new LatLng(40.7326808,-73.9843407));
coordinates.add(new LatLng(40.7336808,-73.9853407));
coordinates.add(new LatLng(40.7346808,-73.9893407));

PolylineOptions polyline = new PolylineOptions();
polyline.addAll(coordinates);
polyline.width(3);
polyline.color(Color.BLUE);
mapboxMap.addPolyline(polyline);
}

private void setPoygon(MapboxMap mapboxMap) {
List<LatLng> coordinates = new ArrayList<>();
coordinates.add(new LatLng(40.7306808,-73.9843407));
coordinates.add(new LatLng(40.7316808,-73.9833407));
coordinates.add(new LatLng(40.7306808,-73.9833407));
coordinates.add(new LatLng(40.7356808,-73.9853407));

PolygonOptions polygon = new PolygonOptions();
polygon.addAll(coordinates);
polygon.fillColor(Color.rgb(255, 102, 0));
polygon.strokeColor(Color.BLACK);
mapboxMap.addPolygon(polygon);
}

private void initializeMapView(MapView mapview, MapboxMap mapboxmap) {
mapview.setStyleUrl(Style.MAPQUEST_STREETS);
mapboxmap.moveCamera(CameraUpdateFactory.newLatLngZoom(NY, 8));
}

private void enableTraffic(MapboxMap mapboxmap) {
mapboxmap.setTrafficFlowLayerOn();
}

private void enableIncidents(MapboxMap mapboxMap) {
mapboxMap.setTrafficIncidentLayerOn();
}

@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}

@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}

@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
}


MQBrianCoakley
The code does not add any
The code does not add any button to the app and does not turn on the device gps functionality. It simply sets the annotation to the device location if available. The application needs to set up device permission before the application has access to it. Are you seeing permission errors in the application log?

hermesuruguay
Yes, permissons are set in

Yes, permissons are set in manifest: 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />

If the code does not do any of the things mentioned above, how can i tell it is working? Where do I see the user's location?

Thanks, Federico.


MQBrianCoakley
The device location will show
The device location will show up as an annotation on the map. The annotation will have a blue/purple circle around it with the approximate accuracy range.   Are you seeing any error messages in the application log?

hermesuruguay
No, it does not. And in the

No, it does not. And in the log I see no error related to that.

Only this: E/emuglGLESv2_enc: a vertex attribute index out of boundary is detected. Skipping corresponding vertex attribute

Can I try something else?

Thanks!

Federico.


MQBrianCoakley
Are you getting the map
Are you getting the map successfully?   If so, is the map getting any annotation on it?   Is the phone's gps function active and working on other apps?   I'm not sure why it's not working.

hermesuruguay
Yes, the map works fine. And

Yes, the map works fine. And phone GPS is active and working fine too.

But still no annotation or circle or anything over my current position.

I have seen in many sites like this, not only the steps and source code, but a full hello world proyect to download. For Android Studio for example. Do you think that is possible? I honestly believe that would save time in both ends!

Thanks!

Federico.


MQBrianCoakley
We don't have that capability
We don't have that capability, yet.

hermesuruguay
Ok, I see, but is there a way

Ok, I see, but is there a way I can help?

I would be glad to submit my hello world app for everyone to download.

It just needs a little tweak for the user location function.

What do you think?

Best, Federico.


MQBrianCoakley
I think it's still a
I think it's still a permissions issue since you have a map but the user's location is not showing up. Here is my current version of the user location sample with permission code included. Note: I am no permissions expert by any means whatsoever and permissions are beyond the MapQuest sdk. But, this works for me...   import android.Manifest; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.mapbox.mapboxsdk.MapboxAccountManager; import com.mapquest.mapping.maps.MapView; import com.mapquest.mapping.maps.MapboxMap; import com.mapquest.mapping.maps.OnMapReadyCallback; public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback { private MapboxMap mMapboxMap; private MapView mMapView; private static final int MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapboxAccountManager.start(getApplicationContext()); setContentView(R.layout.activity_main); mMapView = (MapView) findViewById(R.id.mapquestMapView); mMapView.onCreate(savedInstanceState); mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapboxMap mapboxMap) { mMapboxMap = mapboxMap; if ((ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)){ ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } else { mMapboxMap.setMyLocationEnabled(true); } } }); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION) { if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mMapboxMap.setMyLocationEnabled(true); } } } }

hermesuruguay
Working now!

Thanks Brian! It is working now.

I think it would be nice to have a sample proyect to download, if you want mine i'll be happy to share.

Thanks for everything.

Best, Federico.