[英]How can I get a fake 'current location' when creating an IOS Map with Xamarin Studio and the iPhone Emulator?
問題:
使用Xamarin iPhone模擬器時,當前位置未在地圖上設置。
細節:
我正在嘗試使用Xamarin Studio和iPhone模擬器學習的示例iPhone應用程序在地圖上繪制當前位置。
我顯示了地圖,但是沒有設置當前位置。
我確實被要求使用我的當前位置(我確定我同意/確定要使用..),但是它一直將其居中放置在聯合廣場附近的舊金山市:
每當我運行emulato時,都會看到以下文本:
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,這沒什么太瘋狂的。
有人有什么建議嗎?
您是否嘗試過在模擬器中設置自定義位置?
當我需要在iOs模擬器中驗證位置時,我傾向於結合使用“ 自定義位置”設置和此工具 。 您無需對代碼進行任何更改即可運行; 它只是將設置的位置通過管道傳送到iO中的位置管理器中。
據我所知,該模擬器不支持基於GPS或WiFi的位置,因此它無法像物理設備一樣使用您當前的位置。 也許其他人可以澄清這一點。
有關更多信息,請參見:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.