gpt4 book ai didi

ios - 将从应用程序获取的地理位置传递给 UIWebView

转载 作者:行者123 更新时间:2023-11-29 12:40:42 25 4
gpt4 key购买 nike

我正在开发 iOS 应用程序,在其中一个 View 中,我想将 UIWebView 包含在一个包含 map 的页面中(地址是:https://carsharing.mvg-mobil.de)。该网站需要位置许可,因此一旦用户看到此 View ,就会出现警告:“https://carsharing.mvg-mobil.de/ 想使用您的当前位置。确定/不允许”。

在我的应用程序中,我从 CoreLocation 框架中获取了用户的位置。有没有办法将此位置传递给此 webview 以避免此警报 View ?是否可以通过注入(inject)一些 JavaScript 代码或以某种方式在 URL 中包含地理定位?

最佳答案

好的,我在PhoneGap的源码中找到了解决办法如何使用从 CoreLocation 获取的位置将 JavaScript 代码注入(inject)标准 webview:

int epoch = [newLocation.timestamp timeIntervalSince1970];
float course = -1.0f;
float speed = -1.0f;
NSString* coords = [NSString stringWithFormat:@"coords: { latitude: %f, longitude: %f, altitude: %f, heading: %f, speed: %f, accuracy: %f, altitudeAccuracy: %f }",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude,
newLocation.altitude,
course,
speed,
newLocation.horizontalAccuracy,
newLocation.verticalAccuracy
];

NSString * jsCallBack = [NSString stringWithFormat:@"navigator.geolocation.setLocation({ timestamp: %d, %@ });", epoch, coords];

[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

希望其他人也能从该代码中获益。

关于ios - 将从应用程序获取的地理位置传递给 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25041134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com