Xamarin-GoogleMap类移至特定位置 [英] Xamarin - GoogleMap class move to specific location

查看:96
本文介绍了Xamarin-GoogleMap类移至特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin的内置Map类中,您可以使用Map.MoveToRegion(New Position(latitude, longitude))函数转到地图上的某个区域.我正在使用GoogleMap nuget包,似乎无法找到类似的内置函数. GoogleMap插件是否具有此功能,如果有的话,它是什么?

In Xamarin's inbuilt Map class, you can use the Map.MoveToRegion(New Position(latitude, longitude)) function to go to an area on the map. I am using the GoogleMap nuget package, and can't seem to find a similar in built function. Is there a function for this with the GoogleMap plugin, and if so, what is it?

GoogleMap gMap = new GoogleMap();
//gMap.MoveToRegion(New Position(34.9820, 138.5160)); <-- something like this

推荐答案

要移动区域,请使用以下代码,其中

To move the region use below code where

gMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Latitude, Longitude), Xamarin.Forms.GoogleMaps.Distance.FromMiles(5)));

并使用moveCamera将两个点拟合到边界(电话屏幕)

and use moveCamera to fit two points to bounds(phone screen)

var bounds = Xamarin.Forms.GoogleMaps.Bounds.FromPositions(gMap.Polylines.SelectMany(poly => poly.Positions));
                    var newBoundsArea = CameraUpdateFactory.NewBounds(bounds, 5);
                    await gMap.MoveCamera(newBoundsArea); 

填充5的地方.

这篇关于Xamarin-GoogleMap类移至特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆