Start a new topic

Putting User Current Location(latitude, longitude) to webserver URL

So im trying to get user latitude and longitude into the webserver URL for POI data, here's the URL 

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-6.893238,107.604273&radius=1000&type=point_of_interest&keyword=OlehOleh&key=myKey

 

i have tried that link and it works with no problem, but when i change the location parameter to user current location (latitude & longitude), i have tried this code 

  

POIDATA_SERVER: "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+ World.userLocation.latitude +","+ World.userLocation.longitude +"&radius=1000&type=point_of_interest&keyword=OlehOleh&key=myKey"


when i run the program, the marker won't show up.  


my locationChanged code : 

locationChanged: function locationChangedFn(lat, lon) {

    		// store user's current location in World.userLocation, so you always know where user is
    		World.userLocation = {
    			'latitude': lat,
    			'longitude': lon
    		};

    		// request data if not already present
    		if (!World.initiallyLoadedData) {
    			World.requestDataFromServer(lat, lon);
    			World.initiallyLoadedData = true;
    		} else if (World.locationUpdateCounter === 0) {
    			// update placemark distance information frequently, you max also update distances only every 10m with some more effort
    			World.updateDistanceToUserValues();
    		}

 

 what did i do wrong here ?

Thanks


Hi.

Did you add location permission into your app?, also in the native code you need to provide information about Geolocation(like AR Mode and the location provider in the case of Android). 

What version of the SDK are you running?
Did you follow the examples of the SDK?

What version of Android/IOS did you encounter this issue?

Hi Joaquin, Im using Android SDK
yes im already added location permission and location provider

 

	public LocationProvider(final Context context, LocationListener locationListener) {
		super();
		this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		this.locationListener = locationListener;
		this.context = context;
		this.gpsProviderEnabled = this.locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
		this.networkProviderEnabled = this.locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
	}

 

 

public void onResume() {
		if (this.locationManager != null && this.locationListener != null) {

			// check which providers are available are available
			this.gpsProviderEnabled = this.locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
			this.networkProviderEnabled = this.locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);


			/** is GPS provider enabled? */
			if (this.gpsProviderEnabled) {

				final Location lastKnownGPSLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
				if ( lastKnownGPSLocation != null && lastKnownGPSLocation.getTime() > System.currentTimeMillis() - LOCATION_OUTDATED_WHEN_OLDER_MS ) {
					locationListener.onLocationChanged( lastKnownGPSLocation );
				}
				if (locationManager.getProvider(LocationManager.GPS_PROVIDER)!=null) {
					this.locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, LOCATION_UPDATE_MIN_TIME_GPS, LOCATION_UPDATE_DISTANCE_GPS, this.locationListener );
				}
			}

			/** is Network / WiFi positioning provider available? */
			if ( this.networkProviderEnabled ) {
				final Location lastKnownNWLocation = this.locationManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER );
				if ( lastKnownNWLocation != null && lastKnownNWLocation.getTime() > System.currentTimeMillis() - LOCATION_OUTDATED_WHEN_OLDER_MS ) {
					locationListener.onLocationChanged( lastKnownNWLocation );
				}
				if (locationManager.getProvider(LocationManager.NETWORK_PROVIDER)!=null) {
					this.locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_MIN_TIME_NW, LOCATION_UPDATE_DISTANCE_NW, this.locationListener );
				}
			}

			/** user didn't check a single positioning in the location settings, recommended: handle this event properly in your app, e.g. forward user directly to location-settings, new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ) */
			if ( !this.gpsProviderEnabled || !this.networkProviderEnabled ) {
				Toast.makeText(this.context, "Please enable GPS and Network positioning in your Settings ", Toast.LENGTH_LONG).show();
			}
		}
	}

 

 Hi, did you follow the Wikitude Example and set up these callbacks? 

 @Override
    public void onResume() {
        super.onResume();
        locationProvider.onResume();
        /*
         * The SensorAccuracyChangeListener has to be registered to the Architect view after ArchitectView.onCreate.
         * There may be more than one SensorAccuracyChangeListener.
         */
        architectView.registerSensorAccuracyChangeListener(sensorAccuracyChangeListener);
    }

    @Override
    public void onPause() {
        locationProvider.onPause();
        super.onPause();
        // The SensorAccuracyChangeListener has to be unregistered from the Architect view before ArchitectView.onDestroy.
        architectView.unregisterSensorAccuracyChangeListener(sensorAccuracyChangeListener);
    }

    /**
     * The ArchitectView has to be notified when the location of the device
     * changed in order to accurately display the Augmentations for Geo AR.
     *
     * The ArchitectView has two methods which can be used to pass the Location,
     * it should be chosen by whether an altitude is available or not.
     */
    @Override
    public void onLocationChanged(Location location) {
        final float accuracy = location.hasAccuracy() ? location.getAccuracy() : 1000;
        if (location.hasAltitude()) {
            architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), accuracy);
        } else {
            architectView.setLocation(location.getLatitude(), location.getLongitude(), accuracy);
        }
    } 

  

Login or Signup to post a comment