onury / geolocator

A utility for getting geo-location information via HTML5 and IP look-ups, geocoding, address look-ups, distance and durations, timezone information and more...
https://onury.io/geolocator
MIT License
642 stars 107 forks source link

Crashes when used with Electron #48

Closed pronebird closed 7 years ago

pronebird commented 7 years ago
Uncaught TypeError: Cannot read property '_' of undefined
    at /project/node_modules/geolocator/dist/geolocator.js:2989:19
    at Array.forEach (native)
    at Object.notateGlobalObj (/project/node_modules/geolocator/dist/geolocator.js:2988:17)
    at Function.jsonp (/project/node_modules/geolocator/dist/geolocator.js:3382:36)
    at Function.locateByIP (/project/node_modules/geolocator/dist/geolocator.js:986:37)
    at fallbackToIP (/project/node_modules/geolocator/dist/geolocator.js:704:40)
    at onPositionError (/project/node_modules/geolocator/dist/geolocator.js:716:18)
    at /project/node_modules/geolocator/dist/geolocator.js:2334:18
    at GeoWatcher.clear (/project/node_modules/geolocator/dist/geolocator.js:4933:30)
    at /project/node_modules/geolocator/dist/geolocator.js:2333:29

source:

import geolocator from 'geolocator';

geolocator.config({
  language: "en",
  google: {
    version: "3",
    key: googleApiKey
  }
});

    const options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumWait: 10000,
      desiredAccuracy: 30,
      fallbackToIP: true, 
      addressLookup: true,
      timezone: true
    };

    geolocator.locate(options, (err, loc) => {
      console.log(err, loc);
    });
onury commented 7 years ago

Would you try adding this line right after your import: window.geolocator = geolocator;

Pls see this issue and this SO post I've answered.

pronebird commented 7 years ago

Ha yeah that worked!

onury commented 7 years ago

This is added in v2.1.1.