Mon, 01/16/2017 - 10:50
#1
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.
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.
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.
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.
Yes, this is the text of activity_main.xml:
Thanks for editing the Key Brian. Any ideas to try?
Best, Federico.
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?
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.
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.
Hello Brian, any news in this matter?
Mostly for the 'Use the user location' functionality.
Thanks again! Federico.
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);
}
}
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.
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.
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.
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.
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.