Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geolocation support #41

Closed
velocityzen opened this issue Jan 26, 2016 · 2 comments
Closed

Add geolocation support #41

velocityzen opened this issue Jan 26, 2016 · 2 comments
Milestone

Comments

@velocityzen
Copy link

Right now this code never runs a callback, it is probably something with permissions.

navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
});
@0xWDG
Copy link
Collaborator

0xWDG commented Jan 26, 2016

Difficult. we can enable it via private headers, but we don't do that that will cause App Store submits to rejected.

- (BOOL)webView:(WebView *)sender frame:(WebFrame *)frame requestGeolocationPermission:(WebGeolocation *)geolocation securityOrigin:(WebSecurityOrigin *)origin;

See also:

But i did some research.

 ["city": "Haarlem", "country": "The Netherlands", "alt": -1.8790876865387, "cource": -1.0, "subadministrative": "Haarlem", "ocean": "", "lat": 52.3593304249772, "spreed": -1.0, "name": "Baron de Coubertinstraat 25", "countrycode": "NL", "inlandwater": "", "number": "25", "street": "Baron de Coubertinstraat", "neighborhood": "", "postal": "2037 HA", "lon": 4.66551022283385, "administrative": "North Holland", "poi": ""]
 JS: Added location 

Some technical scripting info.

// For later use.
let locationManager = CLLocationManager()
var currentLocation: [String: Any] = ["lat": 0, "lon": 0, "name": "", "street": "", "number": "", "city": "", "neighborhood": "", "administrative": "", "subadministrative": "", "postal": "", "countrycode": "", "country": "", "inlandwater": "", "ocean": "", "poi": ""]

func websiteWantsLocation() -> Void {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()
    print("Getting location?")
    print(locationManager.location)
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
    let location: CLLocation = locations[0] as! CLLocation

    CLGeocoder().reverseGeocodeLocation(location) {(let myPlacemark, theError) -> Void in
        if (myPlacemark != nil) {
            let place: CLPlacemark = (myPlacemark?.first)!
            self.currentLocation["name"]   = place.name != nil ? place.name! : ""
            self.currentLocation["street"] = place.thoroughfare != nil ? place.thoroughfare! : ""
            self.currentLocation["number"] = place.subThoroughfare != nil ? place.subThoroughfare! : ""
            self.currentLocation["city"] = place.locality != nil ? place.locality! : ""
            self.currentLocation["neighborhood"] = place.subLocality != nil ? place.subLocality! : ""
            self.currentLocation["administrative"] = place.administrativeArea != nil ? place.administrativeArea! : ""
            self.currentLocation["subadministrative"] = place.subAdministrativeArea != nil ? place.subAdministrativeArea : ""
            self.currentLocation["postal"] = place.postalCode != nil ? place.postalCode! : ""
            self.currentLocation["countrycode"] = place.ISOcountryCode != nil ? place.ISOcountryCode! : ""
            self.currentLocation["country"] = place.country != nil ? place.country! : ""
            self.currentLocation["inlandwater"] = place.inlandWater != nil ? place.inlandWater! : ""
            self.currentLocation["ocean"] = place.ocean != nil ? place.ocean! : ""
            self.currentLocation["poi"] = place.areasOfInterest != nil ? place.areasOfInterest! : ""
            print(self.currentLocation)
            // will be called a thousand times or so.

            // Ok inject new java Thing! (Cool!)
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("function navigator.geolocation.getCurrentPosition(callback, error, whatever) {callback('hi')}") // Does not work
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("navigator.geolocation = {getCurrentPosition:function(call, err, we){call('hi')}}") // Does even not work
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("console.log('Added location');")
        }
    }
    currentLocation["lat"] = location.coordinate.latitude
    currentLocation["lon"] = location.coordinate.longitude
    currentLocation["alt"] = location.altitude
    currentLocation["cource"] = location.course
    currentLocation["spreed"] = location.speed
    }

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("Error while updating location " + error.localizedDescription)
}

The problem i got there is i can't rewrite the navigator.geolocation class.

For the rest, if you run:

> navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
},function(position) {
  console.log(position);
});
< undefined

Then WebShell will error (in console)

JS: [object PositionError] 

I don't have a solution ready, sorry.
I'll keep on looking

@0xWDG
Copy link
Collaborator

0xWDG commented Jan 28, 2016

Ok, i'll think i know how to fix it.
Since

navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
},function(position) {
  console.log(position);
});

is not a listener i can directly return the values. (if i save them)
but, i will make a config flag for it, because by default location needs to be disabled.

-> Note to myself: Inject hook, and return dictionary data.

@0xWDG 0xWDG closed this as completed in 772cab3 Jan 29, 2016
@djyde djyde added this to the v0.1.11 milestone Jan 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants