0

问题:
使用 Xamarin iPhone 模拟器时,当前位置未在地图上设置。

详细信息:
我正在尝试在使用 Xamarin Studio 和 iPhone 模拟器学习的示例 iPhone 应用程序中在地图上绘制我当前的位置。

我显示了地图,但没有设置当前位置。

我确实被要求使用我的当前位置(我确定我说是/好的)..但它一直集中在旧金山联合广场附近:(

每当我运行我的模拟器时,我都会看到以下文本弹出:

2013-10-22 09:27:45.018 MyApp [6018:1503] MonoTouch:在 127.0.0.1:10000 上连接到 MonoDevelop 时出现套接字错误:连接被拒绝

所以我不确定这是否与它有关?

好的,让我们看看我得到的一些代码。

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        map.MapType = MKMapType.Standard;
        map.ShowsUserLocation = true;
        map.ZoomEnabled = true;
        map.ScrollEnabled = true;

        map.DidUpdateUserLocation += (sender, e) => {
            if (map.UserLocation != null) 
            {
                CentreMapAtLocation(map.UserLocation.Coordinate.Latitude,
                                    map.UserLocation.Coordinate.Longitude);
            }

            // User denied permission, or device doesn't have GPS/location ability.
            if (!map.UserLocationVisible)
            {
                // TODO: Send the map somewhere or hide the map and show another message.
                //CLLocationCoordinate2D coords = new CLLocationCoordinate2D(37.33233141,-122.0312186); // cupertino
                //MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude));
                //mapView.Region = new MKCoordinateRegion(coords, span);
            }
        };


private void CentreMapAtLocation(double latitude, double longitude)
    {
        CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D (latitude, longitude);
        MKCoordinateRegion mapRegion = MKCoordinateRegion.FromDistance (mapCenter, 10000, 10000);
        map.CenterCoordinate = mapCenter;
        map.Region = mapRegion;
    }

所以没什么太疯狂的,IMO。

有人有什么建议吗?

4

1 回答 1

4

您是否尝试过在模拟器中设置自定义位置?

https://bencoding.files.wordpress.com/2011/12/step2.png

当我需要在 iOs 模拟器中验证位置时,我倾向于结合使用自定义位置设置和此工具。您无需对代码进行任何更改即可使用;它只是将设置的位置通过管道传输到 iOs 中的位置管理器中。

据我所知,模拟器不支持基于 GPS 或 WiFi 的位置,因此它不能像物理设备一样使用您当前的位置。也许其他人可以澄清这一点。

有关详细信息,请参阅:

  1. 在 iPhone 模拟器中设置位置
  2. http://bencoding.com/2011/12/28/setting-you-location-in-the-ios-5-0-simulator/
于 2013-10-21T23:38:00.463 回答