Start a new topic
Solved

onLocationChanged is still not working for android

onLocationChanged is still not working for android


Hello.

let's set the first thing straight. The SDKexample project does compile and run and even shows that it is fetching my current location as the GPS status does blink at the top status bar. The problem is when i try to build my own project after i have followed all the guidelines listed in the "SETUP GUIDE ANDROID" and provided the URL/path to one of the examples (let say it is 4_Point$Of$Interest_1_Poi$At$Location) i get no such status that GPS or Wifi is being used to fetch my location. I suspect that it is the problem with the onLocationChanged method that is not being triggered at all and thus does not return my current coordinates to the function created above. Below is the Main Java file that is handling all the calls and activities with in the app.

 

package com.example.blablabla.wikitudetest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.wikitude.architect.ArchitectView;
import com.wikitude.architect.StartupConfiguration;

public class MainActivity extends AppCompatActivity {

private ArchitectView architectView;

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

this.architectView = (ArchitectView)this.findViewById( R.id.architectView );
final StartupConfiguration config = new StartupConfiguration("blablablablay1FDsOjSznaJ63ZyIrjEkFYvWl5nFaR7BGzga9nwZpKb2eFZ5nzsHdZ3UM6Xl1dPsiMU5b/MgL3cDZgkqqmsgZSW/Ul+6s6a0Wh8VHSZIdoCng0f6L9L06jzKVY0ULEJSILwsbb6YpF2M3tZtp2tLj2Gauleycnldq0sgHpoUk2qyolnH5A1vW36MZo+f1xEAMv2n3KNBBC1aGsG8gr9OwaSLU4IsNLEFA6ye0c0j+8mQpvMiOBg/77OyqJ/8FEeJJph+czOW6hhIirRZa54=");
this.architectView.onCreate(config);
}

@Override
protected void onPostCreate (Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);

architectView.onPostCreate();
try{
this.architectView.load( "file:///android_asset/4_Point$Of$Interest_1_Poi$At$Location/index.html" );
}catch (Exception e)
{}

}

@Override
protected void onResume()
{
super.onResume();
architectView.onResume();

}

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

@Override
protected void onPause()
{
super.onPause();
architectView.onPause();
}
}


 

the Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.blablabla.wikitudetest">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.location" android:required="true" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="true" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="screenSize|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


 

the 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"
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.example.ali2.wikitudetest.MainActivity">

<com.wikitude.architect.ArchitectView android:id="@+id/architectView"
android:layout_width="fill_parent" android:layout_height="fill_parent"/>


</RelativeLayout>


 

the build.gradle file

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "21.1.2"



defaultConfig {
applicationId "com.example.ali2.wikitudetest"
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: )
compile(name: 'wikitudesdk', ext: 'aar')
compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
compile 'com.google.zxing:core:3.2.0'
}

repositories {
flatDir{
dirs 'libs'
}
}

 

and the custom index.html file if i am not using the example itself

<html>
<head>
<script src="architect://architect.js"></script>
</head>
<body>

</body>

<script>

var loaded = false;

function locationChanged(lat, lon, alt, acc)
{

alert('Location received');
if(!loaded)
{

var marker_image = new AR.ImageResource("assets/marker_idle.png");

var marker_loc = new AR.GeoLocation(lat+0.05, lon, alt+26);

var marker_drawable = new AR.ImageDrawable(marker_image, 8);

var marker_object = new AR.GeoObject(marker_loc, {
drawables: {
cam:
}
});



var marker_image = new AR.ImageResource("assets/Logo_512x512_08.png");

var marker_loc = new AR.GeoLocation(lat+0.10, lon+0.05, alt);

var marker_drawable = new AR.ImageDrawable(marker_image, 8);

var marker_object = new AR.GeoObject(marker_loc, {
drawables: {
cam:
}
});



AR.logger.debug("Added marker");

loaded = true;
}

}

AR.logger.activateDebugMode();

AR.context.onLocationChanged = locationChanged;
AR.context.onLocationChanged = function (lat, lon, alt, acc)
{

alert('Location received');
var marker_image = new AR.ImageResource("assets/marker_idle.png");

var marker_loc = new AR.GeoLocation(lat+0.05, lon, alt);

var marker_drawable = new AR.ImageDrawable(marker_image, 8);

var marker_object = new AR.GeoObject(marker_loc, {
drawables: {
cam:
}
});
}
</script>

</html>

whether i activate the onLocationChanged by giving it reference of the variable(in your case "var World") or by associating a function with it, the app doesnt bahave the same way as it does in the SDK Examples app.

I have compiled this code on HTC desire 830 with android v5.0.1(API 22) and Samsung S3 with android v4.3(API 18) & v4.4.4(API 19).



I have read a couple of threads here but to no avail. https://support.wikitude.com/support/search/topics?term=Wikitude+Cordova+onLocatioChanged+not+triggered       https://support.wikitude.com/support/search/topics?term=AR+application+not+showing+POI+on+Galaxy+S4         https://support.wikitude.com/support/search/topics?term=Problem+with+POI.         https://support.wikitude.com/support/search/topics?term=Problem+with+POI.             https://support.wikitude.com/support/search/topics?term=GeoLocation+relative+to+my+location                     https://support.wikitude.com/support/search/topics?term=Sample+app+doesn't+show+anything    

Please do point out the problem as soon as possible.

Thank you.

Hello,

for android the wikitude sdk does not include location management so you need to implement this yourself and call architectView.setLocation(double lat, double lon, double alt, float accuracy).
You can see an example of this in the wikitude sample application AbstractArchitectCamActivity.onCreate(). Please note that a better way to get the location is by using the google play service.

Best regards,
Alex

1 person likes this

Thanks a lot Mr. Alex that worked for me. What I didn’t realize then was that I’ll have to provide location separately using google API(more specifically using locationmanager). I do appreciate your on time response.

Best regards,

Ali.

 

Login or Signup to post a comment