如何在iOS模拟器中查看当前的USER位置。

时间:2015-02-01 01:32:09

标签: ios objective-c xcode mapkit core-location

我正在使用核心位置和地图套件来抓取用户当前位置并将其指向地图上。我在info.plist文件中添加了所需的键(因为我有iOS 8 SDK和Xcode 6),并使用CLLocationManagerDelegate和必要的代码来显示我的纬度和放大器。经度,并确定我在地图上的位置。

虽然当我运行应用程序时,我看到苹果Cupertino是我当前的位置。我检查了 DEBUG>位置之类的设置,但这不是我想要的。我不想想要使用GPX文件模拟位置,我想要做的就是在Simulator上查看我当前的位置。我还使用了示例项目从here找到我,我可以看到相同的结果,即我的位置显示为Cupertino。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,所以我刚刚实现了simple Mac OS App,将iOS模拟器的位置设置为Mac的位置。

它的工作方式是使用CLLocationManager获取Mac的位置,然后使用以下AppleScript在模拟器中设置此位置:

tell application "iOS Simulator"
    activate
end tell   
tell application "System Events"
    tell process "iOS Simulator
        tell menu bar 1
            tell menu bar item "Debug"
                tell menu "Debug"
                    tell menu item "Location"
                        click
                        tell menu "Location"
                            click menu item "Custom Location…"
                        end tell
                    end tell
                end tell
            end tell
        end tell

        tell window 1
            set value of text field 1 to latitude
            set value of text field 2 to longitude
            click button "OK"
        end tell

   end tell
end tell

上面的脚本来自this SO回答,但稍微更新了以便与新的iOS模拟器一起使用。

我希望它可以帮助您,随意分叉和协作。