java - Location mocking - google map detects the movement but my own application not triggering location change


Question: 

I am facing a strange issue. I modified official mock provider source code provided by google to mock some route for my application.

Using this code.

mockLocation.setElapsedRealtimeNanos(elapsedTimeNanos);
                        mockLocation.setTime(currentTime);

                        // Set the location accuracy, latitude, and longitude
                        mockLocation.setAccuracy(mLocationList.get(index).getAccuracy());
                        mockLocation.setLatitude(mLocationList.get(index).getLatitude());
                        mockLocation.setLongitude(mLocationList.get(index).getLongitude());
                        mockLocation.setSpeed(mLocationList.get(index).getGpsSpeed());
                        mockLocation.setBearing(80);
                        mockLocation.setAltitude(mLocationList.get(index).getAltitude());



                        // Inject the test location into Location Services
                        LocationServices.FusedLocationApi.setMockLocation(mLocationClient,mockLocation);

Google map detects this movement but my application is not getting location updates

any idea?




1 Answer: 

Dont you looping this whole process, something like below ?

private void startSpoofing(){
    LocationServices.FusedLocationApi.setMockMode(mGoogleApiClient, true);
    while (mRunning) {
        LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, l);
        l.setTime(System.currentTimeMillis());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
        }

        try {
            Thread.sleep(TIME_BETWEEN_UPDATES_MS);
        } catch (Exception e) {}
    }
}

Whenever you loop this, onLocationChanged method will be triggered

 

More Articles


openssl - Send Push with .p8 and PHP

I need to send Push notifications through PHP script by using .p8 file and found following code in similar question asked here.<?php $keyfile = 'AuthKey_AABBCC1234.p8'; # <- Your AuthKey file $keyid = 'AABBCC1234'; # <- Your Key ID $teamid = 'AB12

java - log4j directs all log output to stdout even though it's not supposed to

In my log4j.properties I have:log4j.rootLogger=DEBUG,stdoutlog4j.logger.notRootLogger=DEBUG,somewhereelseThe appenders stdout and somewhereelse are both configured properly, stdout writes to the console and somewhereelse writes to a file.In my code in each class either I set either:static Logger log

clone a git repository with SSH and libgit2sharp

I'm trying to use the library "libgit2sharp" to clone a repository via a SSH key and... I can't find anything... I can clone it via "https" but what I'd like to do is using an SSH key. It's really unclear if it is supported or not.


Split String With Numbers in R

This question already has an answer here: Split a string by any number of spaces 2 answers

Access remote git repo via ssh, using libgit2sharp

I'm trying to get a simple working example for cloning or accessing a remote git repository via ssh. After adding nuget package LibGit2Sharp-SSH v1.0.22, got a .Net Framework v4.6.1 console application like this:using LibGit2Sharp;using System;using System.IO;class Program{ static void Main(strin

android - Can't find class [org/drinkless/td/libcore/telegram/TdApi$Object]

I am getting this error "Can't find class [org/drinkless/td/libcore/telegram/TdApi$Object]" but I haven't used this class anywhere in my project.I haven't used that class anywhere.But i am getting the above errorCan anyone please let me know how to solve the above error.


How do I cross-compile a Linux kernel to a MIPS little endian host?

The kernel in question is 2.6.18. If I callmake ARCH=mips CROSS_COMPILE=mipsel-linux- menuconfigthere will be only the option to build a big endian kernel in the menu. If I use ARCH=mipsel, it will complain about not having an arch/mipsel dir.How's this done?

php - Key for HMAC Algorithm

How to generate the secret key for the HMAC algorithm as I have to use it for data verification at the other clients end?Thanks in advance.

android - Why getLastKnownLocation(provider) doesn't return null after clearTestProviderLocation(provider)

I was assuming that getLastKnownLocation does return null for a given provider after calling clearTestProviderLocation for same provider.Why ? because documentation says for clearTestProviderLocation; Removes any mock location associated with the given provider.public void test() throws SecurityExc

android - Mock Location permission issue on release app

I developed Fake GPS application and all my codes work nicely on debug mode.When i try "mock location" on **release version**, i got this error;java.lang.SecurityException: Requires `ACCESS_MOCK_LOCATION` permissionI already had ACCESS_MOCK_LOCATION in debug/AndroidManifest file.<uses-permission