Skip to content

Instantly share code, notes, and snippets.

@3t14
Created January 28, 2017 00:10
Show Gist options
  • Save 3t14/c0ec497967d48a31704e221ba36aad6e to your computer and use it in GitHub Desktop.
Save 3t14/c0ec497967d48a31704e221ba36aad6e to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using Plugin.Geolocator;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace HelloMap
{
public class App : Application
{
Map map;
public App()
{
map = new Map(
MapSpan.FromCenterAndRadius( // 描画対象の範囲の生成
new Position(39.7021981, 141.1305283), // 中央位置
Distance.FromKilometers(2))) // 中央位置からの距離
{
IsShowingUser = true, // 現在の位置情報の描画
HeightRequest = 200, // 高さ(ピクセル)
WidthRequest = 960, // 幅(ピクセル)
VerticalOptions = LayoutOptions.FillAndExpand
};
// The root page of your application
var content = new ContentPage
{
Title = "HelloMap",
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
Text = "Welcome to Xamarin FormsMaps!"
},
map // 地図の描画
}
}
};
MainPage = new NavigationPage(content);
}
protected override void OnStart()
{
// Handle when your app starts
updateLocation();
}
// update location
public async Task updateLocation()
{
var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
map.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(position.Latitude, position.Longitude),
Distance.FromKilometers(1)));
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment