Files
vendor_redroid/gps/set_gps_location.sh

83 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Redroid GPS位置设置脚本
# 用法: ./set_gps_location.sh <纬度> <经度>
# 示例: ./set_gps_location.sh 39.904989 116.405285
if [ $# -ne 2 ]; then
echo "用法: $0 <纬度> <经度>"
echo ""
echo "示例位置:"
echo " 北京天安门: $0 39.904989 116.405285"
echo " 上海外滩: $0 31.239666 121.499809"
echo " 广州塔: $0 23.109831 113.324504"
echo " 深圳地王: $0 22.544249 114.095298"
echo " 杭州西湖: $0 30.281026 120.019348"
echo ""
echo "坐标范围:"
echo " 纬度: -90 到 90"
echo " 经度: -180 到 180"
exit 1
fi
LATITUDE=$1
LONGITUDE=$2
# 验证纬度范围
if (( $(echo "$LATITUDE < -90.0 || $LATITUDE > 90.0" | bc -l) )); then
echo "错误: 纬度必须在 -90 到 90 之间"
exit 1
fi
# 验证经度范围
if (( $(echo "$LONGITUDE < -180.0 || $LONGITUDE > 180.0" | bc -l) )); then
echo "错误: 经度必须在 -180 到 180 之间"
exit 1
fi
GPS_FILE="/data/vendor/gps/custom_location.txt"
echo "设置GPS位置为: 纬度 $LATITUDE, 经度 $LONGITUDE"
# 检查设备连接
if ! adb devices | grep -q "device$"; then
echo "错误: 未找到连接的Android设备"
echo "请确保:"
echo "1. 设备已连接并启用USB调试"
echo "2. 已授权计算机的USB调试请求"
exit 1
fi
# 创建临时文件
TEMP_FILE=$(mktemp)
echo "$LATITUDE,$LONGITUDE" > "$TEMP_FILE"
# 推送到设备
echo "正在更新GPS位置文件..."
adb push "$TEMP_FILE" "$GPS_FILE"
if [ $? -eq 0 ]; then
echo "✅ GPS位置更新成功"
# 设置正确权限
adb shell "chown system:system $GPS_FILE"
adb shell "chmod 644 $GPS_FILE"
# 验证文件内容
echo "📍 当前GPS位置"
adb shell "cat $GPS_FILE"
echo ""
echo "💡 提示:"
echo "- 新位置将在下次GPS请求时生效"
echo "- 打开地图应用验证位置是否正确"
echo "- 查看日志: adb logcat | grep -i 'custom.*gps'"
else
echo "❌ GPS位置更新失败"
echo "请检查设备权限和连接状态"
fi
# 清理临时文件
rm -f "$TEMP_FILE"