Start a new topic
Solved

Wikitude SDK - Trying to find out where you are

Hi, 

I'm curently trying to create my own AR app with POI for a school project, so I used the Android Studio SDK.

The problem is that I get a " Trying to find out where you are" error message when I launch my app.

My location service is enabled and my app doesn't appear in "Recent Location Requests" setting.


Here is the error I get (I use the screen from a previous topic I found).


And because I'm not confident about my project structure, here it is:

image


Don't hesitate to ask me questions for further details, and, please,pardon my English as it's not my mother tongue.



Hello Theo,


This message is shown when your location can not be fetched as needed. The "i" icon Trying to find out where you are means the app is waiting for location info. If it keeps showing that, it may be because your GPS is not open or you are testing in house and sometimes that blocks/affects the signal.


Please make sure that you have the location services on for the sample app. The location service has to be authorized by the user (so you can check your phone settings for the app if the location service is enabled to the specific app). For the location handling and the correct set-up please check the set-up guide to make sure you have everything done correctly. And you can also check the implementation and documentation for the POIs samples.

Finally, this could also happen because of specific requirements that your device fail to complete. You could try our sample app with several phones and see if this is happening with other phones as well. The minimum requirements that a device should fulfill are:
1. Compass
2. GPS and/or networking positioning
3. Accelerometer

Thanks
Eva


Thanks for your fast answer!

My GPS is enabled and I'm in a big town so no problem about the signal.


As I said, the app is not requesting to access the location service, so I can't authorized it especially.


I tested it with differents phones (Samsung Galaxy S6 included) so requirements are fine.

Thanks again,

Theo


Ok, so I restarted all the project from the beginning, all is now clean. But, there is always the same problem.

If I enter longitude and latitude" manually in the source code everything is working great, but with the raw SDK I get the error message.

I tested it with different devices and all location options enabled.

Hello Théo,

did you solve the problem?

I have the same problem, would appreciate it if you tell me what to do.

Didn't solved it entirely, did another post on the support but get no answer :(

We get some better results while trying to add our own location data with the Google API.


The first of us who find give it to the other :) 

Sure, once I find a solution i will tell you.

but could you please tell me how did you add your own location data?


Hello,

Sorry that you had to struggle with this one. I provide you the solution below.

On Android the Wikitude SDK does not implement a location strategy to trigger location updates. This means that you have to implement this yourself. There are two ways that you can do that. The first one is by passing the location to the SDK by calling architectView.setLocation(). A sample implementation can be found in the AbstractArchitectCamActivity. The second way is by using Google Location services. This is a documentation provided by Google demonstrating how to make your app location aware. In addition, you can refer to the code on github here regarding GoogleSamples with android play location and in this specific one regarding location updates.


I believe this is all the information you need in order to display your own POIs.


Thanks

Eva


 

Hello Théo, 

I don't know if you still have the problem or not but I kinda found a solution for detecting the location

first I used this code

  mainActivity.java import android.Manifest;

import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.Uri; import android.os.Build; import android.provider.Settings; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;public class MainActivity extends AppCompatActivity {    private Button btn;     private TextView tv;     private LocationManager locationManager;     private LocationListener locationListener;     private String[] perms = {"android.permission.ACCESS_COARSE_LOCATION",             "android.permission.ACCESS_FINE_LOCATION",             "android.permission.INTERNET"};   @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         btn = (Button) findViewById(R.id.btn);         tv = (TextView) findViewById(R.id.tv);         locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);         locationListener = new LocationListener() {            @Override             public void onLocationChanged(Location location) {                 tv.setText("\n" + location.getLatitude() + "   " + location.getLongitude());                 Intent intent = new Intent(android.content.Intent.ACTION_VIEW,                         Uri.parse("geo:0,0?q="+ location.getLatitude()+ "," + location.getLongitude()+ " (" + "ali" + ")"));                 startActivity(intent);             }           @Override             public void onStatusChanged(String provider, int status, Bundle extras) {            }           @Override             public void onProviderEnabled(String provider) {            }           @Override             public void onProviderDisabled(String provider) {                 Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);                 startActivity(intent);             }         };        if(shouldAskPermission()) {             requestPermissions(perms, 1);         }else {             configureButton();         }    }    private void configureButton() {         btn.setOnClickListener(new View.OnClickListener() {            @Override             public void onClick(View v) {                 locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, locationListener);             }         });     }    private boolean shouldAskPermission(){         return(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);     }   @Override     public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {         switch (requestCode) {             case 1 :                 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {                     configureButton();                 } else {                     Toast.makeText(MainActivity.this, "Location Denied", Toast.LENGTH_SHORT)                             .show();                 }                 break;             default:                 super.onRequestPermissionsResult(requestCode, permissions, grantResults);         }     }}actviitymain.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"     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="com.aliishamayleh.location.MainActivity">    <Button         android:id="@+id/btn"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="get location"         android:layout_marginTop="111dp"/>    <TextView         android:id="@+id/tv"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="text"         android:layout_centerInParent="true"/> </RelativeLayout>add these permissions     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>



you can find it as a comment in this video https://www.youtube.com/watch?v=QNb_3QKSmMk


then I changed the code a bit and added some codes from AbstractArchitectCamActivity and implemented the ArchitectViewHolderInterface 

my code is 


public class MainActivity extends AppCompatActivity implements ArchitectViewHolderInterface {
ArchitectView architectView;
protected Location lastKnownLocaton;
private Button btn;
protected ILocationProvider locationProvider;
private TextView tv;
private LocationManager locationManager;
private LocationListener locationListener;

protected JSONArray poiData;

protected boolean isLoading = false;
private String[] perms = {"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.INTERNET"};
Location location;
private static final int WIKITUDE_PERMISSIONS_REQUEST_CAMERA = 1;





protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, WIKITUDE_PERMISSIONS_REQUEST_CAMERA);
}

this.architectView = (ArchitectView) this.findViewById(R.id.architectView);
final ArchitectStartupConfiguration config = new ArchitectStartupConfiguration();
config.setLicenseKey(" ********** ");
this.architectView.onCreate(config);

btn = (Button) findViewById(R.id.btn);
tv = (TextView) findViewById(R.id.tv);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
tv.setText("\n" + location.getLatitude() + " " + location.getLongitude());
if (location!=null) {
// sore last location as member, in case it is needed somewhere (in e.g. your adjusted project)
lastKnownLocaton = location;
if ( architectView != null ) {
// check if location has altitude at certain accuracy level & call right architect method (the one with altitude information)
if ( location.hasAltitude() && location.hasAccuracy() && location.getAccuracy()<7) {
architectView.setLocation( location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy() );
} else {
architectView.setLocation( location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 2000 );
}
}
}
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}
};

this.locationProvider = getLocationProvider( this.locationListener );
if(shouldAskPermission()) {
requestPermissions(perms, 1);
}else {
configureButton();
}

}

private void configureButton() {
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, locationListener);


}
});
}

private boolean shouldAskPermission(){
return(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case 1 :
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
configureButton();
} else {
Toast.makeText(MainActivity.this, "Location Denied", Toast.LENGTH_SHORT)
.show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}




@Override
protected void onPostCreate(Bundle saveInstancestate) {
super.onPostCreate(saveInstancestate);
architectView.onPostCreate();
try {
// load content via url in architectView, ensure '<script src="architect://architect.js"></script>' is part of this HTML file, have a look at wikitude.com's developer section for API references
this.architectView.load("file:///android_asset/poi/index.html" );

if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) {
// set the culling distance - meaning: the maximum distance to render geo-content
this.architectView.setCullingDistance( this.getInitialCullingDistanceMeters() );
}
} catch (IOException e) {
e.printStackTrace();
}

}
@Override
protected void onResume() {
super.onResume();
architectView.onResume();
if ( this.locationProvider != null ) {
this.locationProvider.onResume();

}}


@Override
protected void onDestroy() {
super.onDestroy();
architectView.onDestroy();
if ( this.architectView != null ) {
this.architectView.clearCache();
this.architectView.onDestroy();
}

}

@Override
protected void onPause() {
super.onPause();
architectView.onPause();
if (this.locationProvider != null) {
this.locationProvider.onPause();
}
}
@Override
public String getARchitectWorldPath() {
return null;
}

@Override
public ArchitectView.ArchitectUrlListener getUrlListener() {
return null;
}

@Override
public int getContentViewId() {
return 0;
}

@Override
public String getWikitudeSDKLicenseKey() {
return null;
}

@Override
public int getArchitectViewId() {
return 0;
}

@Override
public ILocationProvider getLocationProvider(LocationListener locationListener) {
return null;
}

@Override
public ArchitectView.SensorAccuracyChangeListener getSensorAccuracyListener() {
return null;
}

@Override
public float getInitialCullingDistanceMeters() {
return 0;
}

@Override
public ArchitectView.ArchitectWorldLoadedListener getWorldLoadedListener() {
return null;
}
protected void injectData() {
if (!isLoading) {
final Thread t = new Thread(new Runnable() {

@Override
public void run() {

isLoading = true;

final int WAIT_FOR_LOCATION_STEP_MS = 2000;

while (lastKnownLocaton==null && !isFinishing()) {

runOnUiThread(new Runnable() {

@Override
public void run() {
Toast.makeText(MainActivity.this, R.string.location_fetching, Toast.LENGTH_SHORT).show();
}
});

try {
Thread.sleep(WAIT_FOR_LOCATION_STEP_MS);
} catch (InterruptedException e) {
break;
}
}

if (lastKnownLocaton!=null && !isFinishing()) {
// TODO: you may replace this dummy implementation and instead load POI information e.g. from your database
poiData = getPoiInformation(lastKnownLocaton, 20);
callJavaScript("World.loadPoisFromJsonData", new String[] { poiData.toString() });
}

isLoading = false;
}
});
t.start();
}
}

/**
* call JacaScript in architectView
* @param methodName
* @param arguments
*/
private void callJavaScript(final String methodName, final String[] arguments) {
final StringBuilder argumentsString = new StringBuilder("");
for (int i= 0; i<arguments.length; i++) {
argumentsString.append(arguments[i]);
if (i<arguments.length-1) {
argumentsString.append(", ");
}
}

if (this.architectView!=null) {
final String js = ( methodName + "( " + argumentsString.toString() + " );" );
this.architectView.callJavascript(js);
}
}

/**
* loads poiInformation and returns them as JSONArray. Ensure attributeNames of JSON POIs are well known in JavaScript, so you can parse them easily
* @param userLocation the location of the user
* @param numberOfPlaces number of places to load (at max)
* @return POI information in JSONArray
*/
public static JSONArray getPoiInformation(final Location userLocation, final int numberOfPlaces) {

if (userLocation==null) {
return null;
}

final JSONArray pois = new JSONArray();

// ensure these attributes are also used in JavaScript when extracting POI data
final String ATTR_ID = "id";
final String ATTR_NAME = "name";
final String ATTR_DESCRIPTION = "description";
final String ATTR_LATITUDE = "latitude";
final String ATTR_LONGITUDE = "longitude";
final String ATTR_ALTITUDE = "altitude";

for (int i=1;i <= numberOfPlaces; i++) {
final HashMap<String, String> poiInformation = new HashMap<String, String>();
poiInformation.put(ATTR_ID, String.valueOf(i));
poiInformation.put(ATTR_NAME, "POI#" + i);
poiInformation.put(ATTR_DESCRIPTION, "This is the description of POI#" + i);
double[] poiLocationLatLon = getRandomLatLonNearby(userLocation.getLatitude(), userLocation.getLongitude());
poiInformation.put(ATTR_LATITUDE, String.valueOf(poiLocationLatLon[0]));
poiInformation.put(ATTR_LONGITUDE, String.valueOf(poiLocationLatLon[1]));
final float UNKNOWN_ALTITUDE = -32768f; // equals "AR.CONST.UNKNOWN_ALTITUDE" in JavaScript (compare AR.GeoLocation specification)
// Use "AR.CONST.UNKNOWN_ALTITUDE" to tell ARchitect that altitude of places should be on user level. Be aware to handle altitude properly in locationManager in case you use valid POI altitude value (e.g. pass altitude only if GPS accuracy is <7m).
poiInformation.put(ATTR_ALTITUDE, String.valueOf(UNKNOWN_ALTITUDE));
pois.put(new JSONObject(poiInformation));
}

return pois;
}

/**
* helper for creation of dummy places.
* @param lat center latitude
* @param lon center longitude
* @return lat/lon values in given position's vicinity
*/
private static double[] getRandomLatLonNearby(final double lat, final double lon) {
return new double[] { lat + Math.random()/5-0.1 , lon + Math.random()/5-0.1};
}
}

I know it's messy but I wanted to help you

anyway I still got a problem

the app detects the location but it doesnt show any marker on the screen 

still working on it, do you have any idea what is wrong?

Hi!

We managed to do it, here you can find our GitHub link: github.com/ThibautE/ProjetAR

Hope it can help you!


(Try to verify your POI, maybe you re too far or them :) )

Hi!

Thank you for your help, I really appreciate it!

However I tried your project and I got this error : java.lang.ClassCastException

do you have any idea why is that?


about being far from the POI, I havent set any POI I am just using the sample which is supposed to show me random POIs around me, so I don't think that this is the problem.

My mistake, It worked now , 

THANK you Théo , I have been struggling with this problem for like 20 days , I'm so grateful .

No problem! Hope you'll manage to create what you wanted to do ;)

Hi Théo, i copied your project and tried to run but i get unable to resolve symbol AppCompactActivity, so i copied all the code into a new project file and the problem solved. but i get the same problem you faced before which is "Trying to find out where you are". Can you please guide me where you solve it? Thanks

I got some problems with this sometimes. It just depend from my connection to GPS network. Try it outside (it really doesn't work well inside buildings :/ )

Login or Signup to post a comment