Last active
July 6, 2017 14:13
-
-
Save jvandijk/bc8630d6d142e7911d4de322fce7dacf to your computer and use it in GitHub Desktop.
Testing location based apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" to tell process "Xcode" | |
click menu item "cli-spoof-location" of menu 1 of menu item "Simulate Location" of menu 1 of menu bar item "Debug" of menu bar 1 | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.id = 'cli-spoof.test'; | |
exports.cliVersion = '>=3.2'; | |
exports.init = function (logger, config, cli, appc) { | |
cli.on('build.ios.xcodeproject', { | |
pre: function (data) { | |
// don't alter the project when going to production | |
if (data.ctx.deployType === 'production') { | |
return; | |
} | |
logger.info('Add GPX file to project for testing purposes'); | |
var uniqueHex = this.hash('cli-spoof-location.gpx').substr(0, 24).toUpperCase(); | |
var hash = data.args[0].hash; | |
var objects = hash.project.objects; | |
var PBXFileReference = objects['PBXFileReference']; | |
var PBXGroup = objects['PBXGroup']; | |
var mainGroup = objects['PBXProject'][hash.project.rootObject].mainGroup; | |
PBXFileReference[uniqueHex] = { | |
isa: 'PBXFileReference', | |
fileEncoding: 4, | |
lastKnownFileType: 'text', | |
name: 'cli-spoof-location.gpx', | |
path: 'path/to/gpx/cli-spoof-location.gpx', | |
sourceTree: '"<group>"' | |
}; | |
PBXFileReference[uniqueHex + '_comment'] = 'cli-spoof-location.gpx'; | |
PBXGroup[mainGroup].children.unshift({ | |
value: uniqueHex, | |
comment: 'cli-spoof-location.gpx' | |
}); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import process from 'child_process'; | |
import sleep from 'system-sleep'; | |
function locationUpdate(coord, delay) { | |
sleep(delay * 1000); | |
if (platform === 'ios') { | |
fs.writeFileSync('cli-spoof-location.gpx', | |
`<gpx creator="Xcode" version="1.1"><wpt lat="${coord.latitude.toFixed(6)}" lon="${coord.longitude.toFixed(6)}"><name>cli-spoof-location</name></wpt></gpx>` | |
); | |
process.exec('osascript autoclick.applescript', (error) => { | |
if (error) { | |
console.log(error.message); | |
return; | |
} | |
}); | |
return; | |
} | |
if (platform === 'android') { | |
// https://github.com/amotzte/android-mock-location-for-development | |
process.exec(`adb shell am broadcast -a send.mock -e lat ${coord.latitude} -e lon ${coord.longitude}`, | |
(error) => { | |
if (error) { | |
console.log(error.message); | |
return; | |
} | |
} | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geolib from 'geolib'; | |
const speed = 25; | |
let previous = { | |
coord: null, | |
delay: 0, | |
}; | |
[array of coordinates].forEach((coordinate) => { | |
previous = nextPoint(previous.coord, { | |
latitude: coordinate[0], | |
longitude: coordinate[1], | |
}, previous.delay); | |
}); | |
function nextPoint(current, next, delay) { | |
let distance = 0, | |
bearing = 0, | |
intermediate, | |
nextMove = delay; | |
if (current !== null) { | |
distance = geolib.getDistance(current, next); | |
if (distance > speed) { | |
nextMove = 1; // move in meters per second | |
bearing = geolib.getBearing(current, next); | |
intermediate = geolib.computeDestinationPoint(current, speed, bearing); | |
locationUpdate(intermediate, nextMove); | |
return nextPoint(intermediate, next, nextMove); | |
} | |
nextMove = (distance / speed); | |
} | |
locationUpdate(next, nextMove); | |
return { | |
coord: next, | |
delay: nextMove, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment