在WP8和WP7上使用BingMapsTask - 结果不同

时间:2013-10-20 17:09:51

标签: c# windows-phone-7 windows-phone-8

所以我一直在使用BingMapsTask,因为wp7显示了用户在应用程序中选择的特定位置。 但是从wp8开始,行为发生了变化!我们怎样才能使用BingMapsTaks?

要运行此代码,请务必将区域设置更改为BELGIUM - DUTCH。执行此操作时,代码将在WP7模拟器中显示正确的位置,但在WP8上它不会! (有关设置和结果,请参阅图像) Demo app on GitHub

GeoCoordinate location = new GeoCoordinate(51.40205, 4.46802);

BingMapsTask task = new BingMapsTask();
task.Center = location;
task.SearchTerm = location.ToString();
task.ZoomLevel = 9;
task.Show();

Region settings

GOOD

Good result

BAD

Bad result

3 个答案:

答案 0 :(得分:2)

我想我已经看到过与BingMapsDirectionTask类似的东西:它仅在手机的区域设置设置为美国时才有效。解决方案是在启动任务之前设置当前线程的文化:

            BingMapsDirectionsTask Direction = new BingMapsDirectionsTask();
            LabeledMapLocation start = new LabeledMapLocation(...);
            LabeledMapLocation End = new LabeledMapLocation(...);
            Direction.Start = start;
            Direction.End = End;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            Direction.Show();

(有关此问题的详细信息,例如from MSDN Forums。)

不幸的是,这似乎不适用于BingMapsTask。问题在于SearchTerm:如果删除它,地图似乎正确居中但不显示PushPin。

您知道所选坐标的地址吗?如果这样做,您可以将SearchTerm更改为该地址,它应该可以正常工作。

例如,这个应该显示正确的位置:

        GeoCoordinate location = new GeoCoordinate(51.40205, 4.46802);

        BingMapsTask task = new BingMapsTask();
        task.Center = location;
        task.SearchTerm = "Noordeind 51, 2920 Kalmthout, Belgia";
        task.ZoomLevel = 9;
        task.Show();

答案 1 :(得分:0)

如果问题是Windows Phone 8,我建议使用MapsTask,因为它在WP8中是首选的!

此外,代替ToString()尝试使用ToString(CultureInfo.InvarianCulture)

答案 2 :(得分:0)

对于WP7,使用BingMapsTask,WP8使用MapsTask。