Passing geolocation from application to UIWebView

I am developing an iOS application in one of the views that I would like to include in UIWebView with a page containing a map (address: https://carsharing.mvg-mobil.de ). The website requires permission to host, so as soon as the user is presented with this view, a warning will appear: " https://carsharing.mvg-mobil.de/ would like to use your current OK / Do not allow".

In my application, I have the location of the user derived from the CoreLocation structure. Is there a way to submit this location to this webview to avoid this warning? Would it be possible if you enter some kind of JavaScript code, or perhaps somehow include geolocation in the URL?

+1
ios objective-c geolocation uiwebview
source share
2 answers

OK, I found a solution in PhoneGap source code, how to add JavaScript code in standrad webview with location selected from CoreLocation:

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]; 

Hope someone else can benefit from this code.

+1
source share

You can invoke JavaScript on the page using

UIWebView <
  stringByEvaluatingJavaScriptFromString:(NSString *)script 
0
source share

All Articles