您应该在单独的线程
private fun getAddress(latitude: Double, longitude: Double) {
viewModelScope.launch {
try {
var addresses: List<Address>
val deferred = this.async(Dispatchers.IO) {
addresses = geocoder!!.getFromLocation(
latitude,
longitude,
1
) // Here 1 represent max location result to returned, by documents it recommended 1 to 5
return@async addresses
}
withContext(Dispatchers.Main) {
val data = deferred.await()
showAddress(data)
}
} catch (e: Exception) {
Log.e("location", e.message!!)
}
}
}
检索地址上调用地理编码器:
private fun showAddress(addresses: List<Address>) {
val address = addresses[0]
.getAddressLine(0) // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
val city = addresses[0].locality
val state = addresses[0].adminArea
val country = addresses[0].countryName
val postalCode = addresses[0].postalCode
val knownName = addresses[0].featureName // Only if available else return NULL
}
您的问题会弄乱水域,因为您正在混合运行时和编译时间逻辑,因为在您的情况下,函数参数的数量和类型取决于某物的运行时值。
现在,您会遇到两个不同的选择:可以进行这项工作(即使在C ++ 14中),但是任何未通过正确参数的呼叫站点都将在运行时无法检测到。这样做的方法是借助 std :: enable_if_t
, exptype()
和 std :: dectval
。我已经为您的示例完成了此操作,并且在C ++ 14模式下为我编译了以下编译:(
#include <iostream>
#include <type_traits>
#include <stdexcept>
enum class Fruit {
Apple,
Orange,
Pear,
};
void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();
struct Processor
{
template<typename... Ts, typename = decltype(processApple(std::forward<Ts>(std::declval<Ts>())...))>
static void process(std::integral_constant<Fruit, Fruit::Apple>, Ts&&... ts)
{
processApple(std::forward<Ts>(ts)...);
}
template<typename... Ts, typename = decltype(processOrange(std::forward<Ts>(std::declval<Ts>())...))>
static void process(std::integral_constant<Fruit, Fruit::Orange>, Ts&&... ts)
{
processOrange(std::forward<Ts>(ts)...);
}
template<typename... Ts, typename = decltype(processPear(std::forward<Ts>(std::declval<Ts>())...))>
static void process(std::integral_constant<Fruit, Fruit::Pear>, Ts&&... ts)
{
processPear(std::forward<Ts>(ts)...);
}
[[noreturn]] static void process(...)
{
// While this is inserted, it should never be called in practice,
// unless there's a programming error.
throw std::invalid_argument("Invalid argument specified to processFruit().");
}
};
template<typename... Args>
void processFruit(Fruit fruit_type, Args&&... args) {
switch (fruit_type) {
case Fruit::Apple:
Processor::process(std::integral_constant<Fruit, Fruit::Apple>(), std::forward<Args>(args)...);
break;
case Fruit::Orange:
Processor::process(std::integral_constant<Fruit, Fruit::Orange>(), std::forward<Args>(args)...);
break;
case Fruit::Pear:
Processor::process(std::integral_constant<Fruit, Fruit::Pear>(), std::forward<Args>(args)...);
break;
default:
break;
}
postProcessing();
return;
}
void processApple(int a, int b)
{
std::cout << "Apple: " << a << " // " << b << std::endl;
}
void processOrange(int c)
{
std::cout << "Orange: " << c << std::endl;
}
void processPear(double d)
{
std::cout << "Pear: " << d << std::endl;
}
void postProcessing()
{
std::cout << "Post processing" << std::endl;
}
int main()
{
processFruit(Fruit::Apple, 4, 8);
processFruit(Fruit::Orange, 15);
processFruit(Fruit::Pear, 1.234);
// The following will only throw an exception, but not fail to compile
//processFruit(Fruit::Pear, 1.234, 77);
return 0;
}
struct处理器
只是为了清理名称空间,它们可能是全局函数。)这里的问题是编译器无法检测到错误的呼叫,请参阅 processFruit的评论(fruat :: pear,1.234,77);
会产生例外,但编译器无法检测到它在编译时。
在我看来,这不是很明智。由于参数取决于 fruit
无论如何类型,我真的看不到当 fruit> fruit
参数仅知道时,您什至无法执行这些功能之一的调用。运行时,因为每个呼叫站点仅适用于一种类型。
而且,如果您确实知道在编译时,可以通过超载以更简单的方式来完成这一点,这也允许更好地编译时间诊断:
#include <iostream>
#include <type_traits>
enum class Fruit {
Apple,
Orange,
Pear,
};
void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();
template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Apple>, Args&&... args)
{
processApple(std::forward<Args>(args)...);
// or put the code of processApple directly in here
}
template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Orange>, Args&&... args)
{
processOrange(std::forward<Args>(args)...);
// or put the code of processOrange directly in here
}
template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Pear>, Args&&... args)
{
processPear(std::forward<Args>(args)...);
// or put the code of processPear directly in here
}
template<Fruit f, typename... Args>
void processFruit2(Args&&... args)
{
processFruit2Helper(std::integral_constant<Fruit, f>(), std::forward<Args>(args)...);
postProcessing();
}
void processApple(int a, int b)
{
std::cout << "Apple: " << a << " // " << b << std::endl;
}
void processOrange(int c)
{
std::cout << "Orange: " << c << std::endl;
}
void processPear(double d)
{
std::cout << "Pear: " << d << std::endl;
}
void postProcessing()
{
std::cout << "Post processing" << std::endl;
}
int main()
{
processFruit2<Fruit::Apple>(4, 8);
processFruit2<Fruit::Orange>(15);
processFruit2<Fruit::Pear>(1.234);
// The following will fail to compile here (which is good)
//processFruit2<Fruit::Pear>(1.234, 77);
return 0;
}
这都说,我怀疑您的代码中存在一些更高级别的设计问题,但我们将无法理解您提供的有限示例。
问题不在您共享的代码中。您的方法或数据可能有问题。
我会在这里猜测,因为您没有共享完整的代码。
如果您使用数据遵循他们的文档,那么您可能会因为有各种各样的对象而陷入困境,并且它们具有一系列字符串。
这就是来自他们的示例的,您需要的是 item.value
和 item.label
而不是 item
:
mounted() {
this.list = this.states.map(item => {
// here you need item.value and item.label
return { value: `value:${item}`, label: `label:${item}` };
});
}
但这只是一个示例,在这里您可能会从API中获取数据,因此您需要检查如何检查该数据是结构化的。
这是您的数据的完整示例 https://codepen.io/jakob_/jakob_/jakob_/pen/pen/grxmqqqn
诚然,它有点隐藏,但是您可以在 monetdbe-examples 存储库:
import monetdbe
database = '/tmp/movies.mdbe'
with monetdbe.connect(database) as conn:
conn.set_autocommit(True)
conn.execute(
"""CREATE TABLE Movies
(id SERIAL, title TEXT NOT NULL, "year" INTEGER NOT NULL)""")
因此,在此示例中,单个参数到 connect
只是您数据库目录的所需路径。这就是您(重新)启动一个数据库,该数据库以持久的方式存储其数据在文件系统上。
请注意,我已故意从实际存储库中的示例中删除了Python行,该示例以注释#开始,如果数据库已经存在
。只是为了使答案中的示例持续。
我尚未运行代码,但我希望如果您连续两次运行此代码,则第二次运行将在执行语句上返回数据库错误,因为 Movies
表应该已经存在。
可以肯定的是,如果您希望数据在计算机的重新启动之间持续存在,请勿使用/tmp
目录。
在另一篇文章中找到了我的答案,希望它对其他人有所帮助:
https://stackoverflow.com/a/56344197/302613
为了确保出现此映射,您需要去控制
面板 - &GT;打开或关闭Windows功能 - &GT; .NET框架4.7
高级服务(或equiv .Net Ver) - &gt; WCF服务 - &GT; http
激活
它有3个步骤:
1-在您的应用程序录音中添加SMS读取和接收权限:
//in android
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
2-创建一种权限检查的方法。3-
public async Task<PermissionStatus> CheckAndRequestSMSPermission()
{
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.Sms>();
if (status == PermissionStatus.Granted)
return status;
if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
{
// Prompt the user to turn on in settings
// On iOS once a permission has been denied it may not be requested again from the application
return status;
}
if (Permissions.ShouldShowRationale<Permissions.Sms>())
{
// Prompt the user with additional information as to why the permission is needed
}
status = await Permissions.RequestAsync<Permissions.Sms>();
return status;
}
进行API调用并获取SMS并使用它。
private async void OnCounterClicked(object sender, EventArgs e)
{
var res= await CheckAndRequestSMSPermission();
if (res.Equals( PermissionStatus.Granted))
{
#if ANDROID
List<string> items=new List<string>();
string INBOX = "content://sms/inbox";
string[] reqCols = new string[] { "_id", "thread_id", "address", "person", "date", "body", "type" };
Android.Net.Uri uri = Android.Net.Uri.Parse(INBOX);
Android.Database.ICursor cursor = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.ContentResolver.Query(uri, reqCols, null, null, null);
if (cursor.MoveToFirst())
{
do
{
string messageId = cursor.GetString(cursor.GetColumnIndex(reqCols[0]));
string threadId = cursor.GetString(cursor.GetColumnIndex(reqCols[1]));
string address = cursor.GetString(cursor.GetColumnIndex(reqCols[2]));
string name = cursor.GetString(cursor.GetColumnIndex(reqCols[3]));
string date = cursor.GetString(cursor.GetColumnIndex(reqCols[4]));
string msg = cursor.GetString(cursor.GetColumnIndex(reqCols[5]));
string type = cursor.GetString(cursor.GetColumnIndex(reqCols[6]));
items.Add(messageId + (","
+ (threadId + (","
+ (address + (","
+ (name + (","
+ (date + (" ,"
+ (msg + (" ," + type))))))))))));
} while (cursor.MoveToNext());
}
#endif
}
}
- 您可以在此处。
我建议开始围绕服务,集团,存储库实施单元测试。然后在有一些逻辑的地方开始测试视图小部件。
之后,也许在复杂方案周围进行了一些集成测试,例如如果我将许多单元测试结合在一起以模拟登录,会发生什么。
不确定在这里了解您的目标,但这是迭代行上的一种方法:
import pandas as pd
eIP = pd.DataFrame({"IP": ["a", "b", "c"]})
for _, row in eIP.iterrows():
print(row.values[0])
# Output
a
b
c
您还可以获取这样的价值的字典:
print(eIP.to_dict()["IP"])
# Output
{0: 'a', 1: 'b', 2: 'c'}
基本上,您可以将数据保存为 userDefaults
中的字符串数组
func save() {
UserDefaults.standard.set(items.map(\.title), forKey: "items")
}
func load() {
let savedItems = UserDefaults.standard.stringArray(forKey: "items") ?? []
items = savedItems.map(Item.init)
}
,并在 .onappear
中调用 load 。
但是,如果有大量项目考虑文档文件夹或核心数据中的文件
- 请使用
{renderlist()}
而不是{renderList}
。 - 使用
{renderList()}
&lt;/datatable.header&gt;
和&lt;/datatable&gt;
...而不是之后&lt;/datatable&gt;
。
这完全取决于您想要的效果,但是对于所示的简单案例,您只需删除第一个(或最后一个,具体取决于您朝哪个方向)元素,然后将其放在缩略图集的末端(或开始)。
这也使事情变得更加响应,因为如果您不想,您不必以PX术语来修复宽度,因为不必记住它们即可移动元素。
const buttonLeft = document.getElementById('slide_left')
const buttonRight = document.getElementById('slide_right')
const container = document.getElementById('slider');
buttonLeft.addEventListener('click', function() {
const last = document.querySelector('#slider > :last-child');
last.remove();
container.prepend(last);
})
buttonRight.addEventListener('click', function() {
const first = document.querySelector('#slider > :first-child');
first.remove();
container.append(first);
})
body {
background-color: #555;
height: 100vh;
display: grid;
align-items: center;
justify-items: center;
font-family: 'Helvetica';
}
div#slide_wrapper {
width: 440px;
display: flex;
justify-content: space-between;
height: fit-content;
}
div#slider {
width: 350px;
display: flex;
height: fit-content;
flex-wrap: nowrap;
overflow: hidden;
}
div.thumbnail {
min-width: 80px;
min-height: 80px;
cursor: pointer;
display: grid;
place-items: center;
font-size: 30px;
}
div.thumbnail:not(:last-child) {
margin-right: 10px;
}
div.thumbnail.c1 {
background-color: darkturquoise;
}
div.thumbnail.c2 {
background-color: goldenrod;
}
div.thumbnail.c3 {
background-color: rebeccapurple;
}
div.thumbnail.c4 {
background-color: salmon;
}
div.thumbnail.c5 {
background-color: lawngreen;
}
div.thumbnail.c6 {
background-color: sienna;
}
div.thumbnail.c7 {
background-color: bisque;
}
div.thumbnail.c8 {
background-color: navy;
}
div#slide_wrapper>button {
height: fit-content;
align-self: center;
font-size: 24px;
font-weight: 800;
border: none;
outline: none;
}
div#slide_wrapper>button:hover {
cursor: pointer;
}
<div id="slide_wrapper">
<button id="slide_left" class="slide_arrow">❮</button>
<div id="slider">
<div class="thumbnail c1 active">1</div>
<div class="thumbnail c2">2</div>
<div class="thumbnail c3">3</div>
<div class="thumbnail c4">4</div>
<div class="thumbnail c5">5</div>
<div class="thumbnail c6">6</div>
<div class="thumbnail c7">7</div>
<div class="thumbnail c8">8</div>
</div>
<button id="slide_right" class="slide_arrow">❯</button>
</div>
如果您确定所有配置都是正确的,那么由于将null值作为ciphered发送到降低或平面文本以供ENRIPTION,因此可能会得到此例外。
这是因为您的工厂构造函数并非无参数,并且当服务提供商试图实例化工厂时,它没有价值来传递“示例”变量。
有两种可能的解决方案:
1-更改工厂的设计,并将“示例”作为变量创建方法而不是构造函数。
或
2-这样注册工厂:
services.AddSingleton(s => new Factory(s.GetService<A>(), "desired string"));
顺便说一句,我不知道您实施该工厂类的用例是什么,但似乎并不是实施它的正确方法。我建议您事先看看:
Nuget软件包注册表是在Gitlab 12.8中引入的,因此版本11.1不存在
The Nuget package registry was introduced in GitLab 12.8 so it won't be present in version 11.1
如何在gitlab nuget软件包上解析404网址?