简体   繁体   English

在脚本中设置Android模拟位置

[英]Setting Android Mock Locations in a Script

I have an Android phone (not an emulator) and I'd like to make a bash script that sets the location of the phone. 我有一部Android手机(不是模拟器),我想制作一个bash脚本来设置手机的位置。 If I have a file that contains my latitude and longitudes like this 如果我的文件包含这样的纬度和经度

45.3453 13.3453
45.3467 13.3501
etc     etc

I want to do something like 我想做类似的事情

#!/bin/bash

for ii in $(cat lat_lon_file); do
    lat=$(echo $ii | cut -f 1)
    lon=$(echo $ii | cut -f 2)
    adb shell setLatLon $lat $lon
done

I'm not sure how I can set locations like this (if at all), is there something I can echo in /proc somewhere? 我不确定如何设置这样的位置(如果有的话),我可以在/ proc某处回显什么吗?

Also, bonus: is there a cleaner way to cut $ii in my script than echo ing and piping? 另外,还有一点好处:在脚本中cut $ii方法是否比echo和管道更清洁?

Your current script does not iterate over lines, it iterates over words. 您当前的脚本不会遍历行,而是遍历单词。 This means that each iteration will only have the latitude or the longitude. 这意味着每次迭代将仅具有纬度或经度。 This correct way to iterate over lines in a file and answers your side question: 这种遍历文件中的行并回答您的侧面问题的正确方法:

while read -r lat lon _; do
   adb shell setLatLon "$lat" "$lon"
done < lat_lon_file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM