wgs84 to gcj02

This commit is contained in:
Tsanie 2022-03-18 14:08:17 +08:00
parent f27b0a2564
commit 7ca377b8c2
7 changed files with 74 additions and 25 deletions

View File

@ -147,6 +147,39 @@ namespace Billing
} }
return status; return status;
} }
private static double TransformLatitude(double x, double y)
{
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));
ret += (20.0 * Math.Sin(6.0 * x * Math.PI) + 20.0 * Math.Sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(y * Math.PI) + 40.0 * Math.Sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.Sin(y / 12.0 * Math.PI) + 320 * Math.Sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
return ret;
}
private static double TransformLongitude(double x, double y)
{
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));
ret += (20.0 * Math.Sin(6.0 * x * Math.PI) + 20.0 * Math.Sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(x * Math.PI) + 40.0 * Math.Sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.Sin(x / 12.0 * Math.PI) + 300.0 * Math.Sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;
return ret;
}
public static (double longitude, double latitude) Wgs84ToGcj02(double longitude, double latitude)
{
var a = 6378245.0;
var ee = 0.00669342162296594323;
var offsetLatitude = TransformLatitude(longitude - 105.0, latitude - 35.0);
var offsetLongitude = TransformLongitude(longitude - 105.0, latitude - 35.0);
var radiusLatitude = latitude / 180.0 * Math.PI;
var magic = Math.Sin(radiusLatitude);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.Sqrt(magic);
offsetLatitude = offsetLatitude * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * Math.PI);
offsetLongitude = offsetLongitude * 180.0 / (a / sqrtMagic * Math.Cos(radiusLatitude) * Math.PI);
return (longitude + offsetLongitude, latitude + offsetLatitude);
}
} }
public class AsyncLazy<T> public class AsyncLazy<T>

View File

@ -5,6 +5,8 @@ namespace Billing.Themes
{ {
public abstract class BaseTheme : ResourceDictionary public abstract class BaseTheme : ResourceDictionary
{ {
public const double DefaultFontSize = 15.0;
public static Color CurrentPrimaryColor => (Color)Application.Current.Resources[PrimaryColor]; public static Color CurrentPrimaryColor => (Color)Application.Current.Resources[PrimaryColor];
public static Color CurrentTextColor => (Color)Application.Current.Resources[TextColor]; public static Color CurrentTextColor => (Color)Application.Current.Resources[TextColor];
public static Color CurrentSecondaryTextColor => (Color)Application.Current.Resources[SecondaryTextColor]; public static Color CurrentSecondaryTextColor => (Color)Application.Current.Resources[SecondaryTextColor];
@ -42,7 +44,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Label)) }, new Setter { Property = Label.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = Label.TextColorProperty, Value = PrimaryMauiColor }, new Setter { Property = Label.TextColorProperty, Value = PrimaryMauiColor },
new Setter { Property = Label.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = Label.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
@ -51,7 +53,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = Entry.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Entry)) }, new Setter { Property = Entry.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = Entry.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = Entry.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
}); });
@ -59,7 +61,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = Editor.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Editor)) }, new Setter { Property = Editor.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = Editor.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = Editor.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
}); });
@ -67,7 +69,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = DatePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(DatePicker)) }, new Setter { Property = DatePicker.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = DatePicker.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = DatePicker.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
}); });
@ -75,7 +77,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = TimePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, new Setter { Property = TimePicker.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = TimePicker.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = TimePicker.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
}); });
@ -83,7 +85,7 @@ namespace Billing.Themes
{ {
Setters = Setters =
{ {
new Setter { Property = Picker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, new Setter { Property = Picker.FontSizeProperty, Value = DefaultFontSize },
new Setter { Property = Picker.FontFamilyProperty, Value = Definition.RegularFontFamily } new Setter { Property = Picker.FontFamilyProperty, Value = Definition.RegularFontFamily }
} }
}); });

View File

@ -16,13 +16,14 @@ namespace Billing.Views
{ {
private static readonly BindableProperty CheckBillProperty = Helper.Create<Command, AddBillPage>(nameof(CheckBill), defaultValue: new Command(() => { }, () => false)); private static readonly BindableProperty CheckBillProperty = Helper.Create<Command, AddBillPage>(nameof(CheckBill), defaultValue: new Command(() => { }, () => false));
private static readonly BindableProperty AmountProperty = Helper.Create<string, AddBillPage>(nameof(Amount)); private static readonly BindableProperty AmountProperty = Helper.Create<string, AddBillPage>(nameof(Amount));
private static readonly BindableProperty NameProperty = Helper.Create<string, AddBillPage>(nameof(Name)); private static readonly BindableProperty NameProperty = Helper.Create<string, AddBillPage>(nameof(Name), defaultValue: string.Empty);
private static readonly BindableProperty CategoryProperty = Helper.Create<Category, AddBillPage>(nameof(Category)); private static readonly BindableProperty CategoryProperty = Helper.Create<Category, AddBillPage>(nameof(Category));
private static readonly BindableProperty WalletProperty = Helper.Create<Account, AddBillPage>(nameof(Wallet)); private static readonly BindableProperty WalletProperty = Helper.Create<Account, AddBillPage>(nameof(Wallet));
private static readonly BindableProperty StoreProperty = Helper.Create<string, AddBillPage>(nameof(Store)); private static readonly BindableProperty StoreProperty = Helper.Create<string, AddBillPage>(nameof(Store));
private static readonly BindableProperty CreatedDateProperty = Helper.Create<DateTime, AddBillPage>(nameof(CreatedDate)); private static readonly BindableProperty CreatedDateProperty = Helper.Create<DateTime, AddBillPage>(nameof(CreatedDate));
private static readonly BindableProperty CreatedTimeProperty = Helper.Create<TimeSpan, AddBillPage>(nameof(CreatedTime)); private static readonly BindableProperty CreatedTimeProperty = Helper.Create<TimeSpan, AddBillPage>(nameof(CreatedTime));
private static readonly BindableProperty NoteProperty = Helper.Create<string, AddBillPage>(nameof(Note)); private static readonly BindableProperty NoteProperty = Helper.Create<string, AddBillPage>(nameof(Note));
private static readonly BindableProperty ViewLocationProperty = Helper.Create<Command, AddBillPage>(nameof(ViewLocation), defaultValue: new Command(() => { }, () => false));
public Command CheckBill => (Command)GetValue(CheckBillProperty); public Command CheckBill => (Command)GetValue(CheckBillProperty);
public string Amount public string Amount
@ -60,7 +61,7 @@ namespace Billing.Views
public Command SelectCategory { get; } public Command SelectCategory { get; }
public Command SelectWallet { get; } public Command SelectWallet { get; }
public Command ViewLocation { get; } public Command ViewLocation => (Command)GetValue(ViewLocationProperty);
public event EventHandler<Bill> BillChecked; public event EventHandler<Bill> BillChecked;
@ -77,7 +78,6 @@ namespace Billing.Views
createDate = date; createDate = date;
SelectCategory = new Command(OnSelectCategory); SelectCategory = new Command(OnSelectCategory);
SelectWallet = new Command(OnSelectWallet); SelectWallet = new Command(OnSelectWallet);
ViewLocation = new Command(() => { }, () => false);
InitializeComponent(); InitializeComponent();
Title = Resource.AddBill; Title = Resource.AddBill;
@ -89,10 +89,11 @@ namespace Billing.Views
this.bill = bill; this.bill = bill;
SelectCategory = new Command(OnSelectCategory); SelectCategory = new Command(OnSelectCategory);
SelectWallet = new Command(OnSelectWallet); SelectWallet = new Command(OnSelectWallet);
#if __ANDROID__ #if __IOS__
ViewLocation = new Command(() => { }, () => false); if (bill != null && bill.Latitude != null && bill.Longitude != null)
#else {
ViewLocation = new Command(OnViewLocation, () => bill != null && bill.Latitude != null && bill.Longitude != null); SetValue(ViewLocationProperty, new Command(OnViewLocation));
}
#endif #endif
InitializeComponent(); InitializeComponent();
Title = Resource.EditBill; Title = Resource.EditBill;
@ -160,6 +161,12 @@ namespace Billing.Views
return; return;
} }
location = await Geolocation.GetLocationAsync(request, tokenSource.Token); location = await Geolocation.GetLocationAsync(request, tokenSource.Token);
#if __IOS__
if (bill == null)
{
SetValue(ViewLocationProperty, new Command(OnViewLocation));
}
#endif
} }
catch (FeatureNotSupportedException) { } catch (FeatureNotSupportedException) { }
catch (FeatureNotEnabledException) { } catch (FeatureNotEnabledException) { }
@ -170,7 +177,7 @@ namespace Billing.Views
} }
finally finally
{ {
SetValue(CheckBillProperty, new Command(OnCheckBill)); SetValue(CheckBillProperty, new Command(OnCheckBill));
} }
} }
@ -292,7 +299,7 @@ namespace Billing.Views
private async void OnViewLocation() private async void OnViewLocation()
{ {
if (bill == null) if (bill == null && location == null)
{ {
return; return;
} }
@ -302,7 +309,13 @@ namespace Billing.Views
} }
using (Tap.Start()) using (Tap.Start())
{ {
var page = new ViewLocationPage(bill); var page = new ViewLocationPage(bill ?? new Bill
{
Name = Name,
Store = Store,
Longitude = location.Longitude,
Latitude = location.Latitude
});
await Navigation.PushAsync(page); await Navigation.PushAsync(page);
} }
} }

View File

@ -17,18 +17,18 @@
<TableView Intent="Settings" HasUnevenRows="True"> <TableView Intent="Settings" HasUnevenRows="True">
<TableSection Title="{r:Text About}"> <TableSection Title="{r:Text About}">
<ui:OptionTextCell Height="36" Title="{r:Text Version}" <ui:OptionTextCell Height="44" Title="{r:Text Version}"
Detail="{Binding Version}"/> Detail="{Binding Version}"/>
</TableSection> </TableSection>
<TableSection Title="{r:Text Feature}"> <TableSection Title="{r:Text Feature}">
<ui:OptionSelectCell Height="36" Title="{r:Text CategoryManage}" <ui:OptionSelectCell Height="44" Title="{r:Text CategoryManage}"
Detail="{r:Text Detail}" Detail="{r:Text Detail}"
Command="{Binding CategoryCommand}"/> Command="{Binding CategoryCommand}"/>
<ui:OptionSwitchCell Height="36" Title="{r:Text SaveLocation}" <ui:OptionSwitchCell Height="44" Title="{r:Text SaveLocation}"
IsToggled="{Binding SaveLocation, Mode=TwoWay}"/> IsToggled="{Binding SaveLocation, Mode=TwoWay}"/>
</TableSection> </TableSection>
<TableSection Title="{r:Text Preference}"> <TableSection Title="{r:Text Preference}">
<ui:OptionEntryCell Height="36" Title="{r:Text PrimaryColor}" <ui:OptionEntryCell Height="44" Title="{r:Text PrimaryColor}"
Text="{Binding PrimaryColor, Mode=TwoWay}" Text="{Binding PrimaryColor, Mode=TwoWay}"
Keyboard="Text"/> Keyboard="Text"/>
<ViewCell Height="120"> <ViewCell Height="120">
@ -42,7 +42,7 @@
</ViewCell> </ViewCell>
</TableSection> </TableSection>
<TableSection Title="{r:Text Diagnostic}"> <TableSection Title="{r:Text Diagnostic}">
<ui:OptionSelectCell Height="36" Title="{r:Text ShareLogs}" <ui:OptionSelectCell Height="44" Title="{r:Text ShareLogs}"
Detail="{Binding ManyRecords}" Detail="{Binding ManyRecords}"
Command="{Binding ShareLogsCommand}"/> Command="{Binding ShareLogsCommand}"/>
</TableSection> </TableSection>

View File

@ -14,7 +14,8 @@ namespace Billing.Views
if (bill.Latitude != null && bill.Longitude != null) if (bill.Latitude != null && bill.Longitude != null)
{ {
var position = new Position(bill.Latitude.Value, bill.Longitude.Value); var (longitude, latitude) = Helper.Wgs84ToGcj02(bill.Longitude.Value, bill.Latitude.Value);
var position = new Position(latitude, longitude);
var mapSpan = new MapSpan(position, 0.01, 0.01); var mapSpan = new MapSpan(position, 0.01, 0.01);
Content = new Map(mapSpan) Content = new Map(mapSpan)
{ {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.2.317" package="org.tsanie.billing" android:installLocation="auto" android:versionCode="17"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.2.318" package="org.tsanie.billing" android:installLocation="auto" android:versionCode="18">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="30" /> <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="30" />
<application android:label="@string/applabel" android:theme="@style/MainTheme" android:requestLegacyExternalStorage="true"></application> <application android:label="@string/applabel" android:theme="@style/MainTheme" android:requestLegacyExternalStorage="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View File

@ -80,9 +80,9 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>18</string> <string>19</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.2.317</string> <string>1.2.318</string>
<key>LSApplicationQueriesSchemes</key> <key>LSApplicationQueriesSchemes</key>
<array> <array>
<string>mailto</string> <string>mailto</string>