Ich habe ein Webview mit HTML erstellt, um aktuelle Benutzer zu laden.ios - Google Maps im Webview lädt nicht den aktuellen Standort
Hier wird Struktur verwendet:
webview.m - Lasten
index.html index.html - zeigt die Daten
info.plist - NSLocationWhenInUseUsageDescription & NSLocationAlwaysUsageDescription hinzugefügt
Hier zwei Situationen:
1) Wenn ich Google Maps in Webview laden - es d oes lädt meinen aktuellen Standort nicht. Der Spinner dreht sich gerade und zeigt eine Karte der Welt.
2) In index.html Ich füge den Code hinzu, um meine aktuelle Position Länge und Breite zu laden. Im Browser des Laptops (nicht xcode) zeigt es meinen Standort an, wenn ich index.html in xcode öffne, zeigt es mir es nicht an.
Wahrscheinlich gibt es etwas hinzuzufügen, damit die App Ihren Standort bekommen kann, z. Im Browser wird um Erlaubnis für den Standort gebeten. In der App fragt es mich das nicht. Hier
ist der Code: webview.m
#import "Webview.h"
@interface Webview()
@end
@implementation Webview
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlAddress= [[NSBundle mainBundle] pathForResource:@"demos/index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath: urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];
[_webView setDelegate:self];
_webView.scrollView.delegate = self;
_webView.scrollView.scrollEnabled = true;
_webView.scrollView.bounces = NO;
[_webView loadRequest:requestObj];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
index.html
Laden Google Maps
<meta http-equiv="refresh" content="0; url=http://maps.google.com/" />
Laden aktuellen Standort
<p>Address:
<div id="address"></div>
<div id="l"></div>
<div id="lo"></div>
</p>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script type="text/javascript">
$(document).ready(function() {
var currgeocoder;
//Set geo location lat and long
navigator.geolocation.getCurrentPosition(function (position, html5Error) {
geo_loc = processGeolocationResult(position);
currLatLong = geo_loc.split(",");
initializeCurrent(currLatLong[0], currLatLong[1]);
});
//Get geo location result
function processGeolocationResult(position) {
html5Lat = position.coords.latitude; //Get latitude
html5Lon = position.coords.longitude; //Get longitude
html5TimeStamp = position.timestamp; //Get timestamp
html5Accuracy = position.coords.accuracy; //Get accuracy in meters
return (html5Lat).toFixed(8) + ", " + (html5Lon).toFixed(8);
}
//Check value is present or
function initializeCurrent(latcurr, longcurr) {
currgeocoder = new google.maps.Geocoder();
console.log(latcurr + "-- ######## --" + longcurr);
if (latcurr != '' && longcurr != '') {
//call google api function
var myLatlng = new google.maps.LatLng(latcurr, longcurr);
return getCurrentAddress(myLatlng);
}
}
//Get current address
function getCurrentAddress(location) {
currgeocoder.geocode({
'location': location
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results[0]);
$("#address").html(results[0].formatted_address);
$("#l").html(html5Lat);
$("#lo").html(html5Lon);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
});
</script>
info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSLocationWhenInUseUsageDescription </key>
<string>Give us permission to use your location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Main</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
</dict>
</plist>
Frage: Wie kann ich meine App die Erlaubnis für den Standort fragen? oder um den Standort sofort zu laden?