Giter Site home page Giter Site logo

elm-lang / geolocation Goto Github PK

View Code? Open in Web Editor NEW
36.0 7.0 9.0 29 KB

Get location data from Elm

Home Page: http://package.elm-lang.org/packages/elm-lang/geolocation/latest

License: BSD 3-Clause "New" or "Revised" License

Elm 75.14% JavaScript 24.86%

geolocation's Introduction

Geolocation in Elm

Your client code is running on someone's device somewhere in the world. This library helps you find out where that device happens to be. If you are lucky, it may even tell you how fast the device is moving!

It is based on the JavaScript Geolocation API. You can read about how to use libraries with tasks and subscriptions in guide.elm-lang.org, particularly the section on The Elm Architecture.

geolocation's People

Contributors

evancz avatar process-bot avatar pzp1997 avatar robertjlooby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

geolocation's Issues

Need help with Task Type

I really could not get Geolocation.now working.

import Geolocation  exposing ( Location )
import Task

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Msgs.SubscribeGeolocation ->
          ( model ,
            Task.attempt processGeolocation Geolocation.now
          )

processGeolocation : Result x a -> Msg
processGeolocation res =
  case res of
    Geolocation.Location location -> Msgs.SaveLocation location
    _ -> Msgs.Submit

Compiler tells me

Cannot find pattern `Geolocation.Location`.

Can someone assist? I'm really stuck.

Newest Safari no longer working with default options passed by Native.Geolocation#fromOptions

With the latest iOS update (10.3, is working with 10.2 - I tested this with multiple devices), Geolocation.now stopped working with default options. Don't know how long this hasn't been working with macOS Sierra, but it certainly doesn't work with 10.12.5. Geolocation.now with default options works in Chrome desktop and mobile, but in Safari it fails.

The cause of the problem is with the default options and the timeout setting:

function fromOptions(options)
{
	return {
		enableHighAccuracy: options.enableHighAccuracy,
		timeout: options.timeout._0 || Infinity,
		maximumAge: options.maximumAge._0 || 0
	};
}

Having timeout = Infinity immediately returns an error in the latest Safari across all platforms. In all the newest versions of Safari, this works exactly the same as passing timeout "0".

This can be tested easily by this snippet:

navigator.geolocation.getCurrentPosition(() => {}, (err) => { console.log(err)}, { timeout: Infinity})

It outputs just the next moment:
[Log] PositionError {code: 3, message: "Timeout expired", PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}

Note that not passing any options works just fine with Safari and every other browser I tested:

navigator.geolocation.getCurrentPosition((result) => {console.log(result)}, (err) => { console.log(err)})

[Log] Geoposition {coords: Coordinates, timestamp: 519569198545}

I've checked MDN documentation once again (https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) and it does say that default option for timeout is Infinity. Seems like Apple decided to do something differently.

Anyway, with current implementation, unspecified (default) options just break the Geolocation API. Is it possible not to pass timeout set to Inifinity when talking to JS?

Why not a Time?

The timeout and TTL are specified using plain integer values. The docs specify a unit (yay!), but Time encodes it in a type. Is there some design constraint that makes Time undesirable here?

Geolocation.Options takes unitless values instead of Times

The record for Geolocation.Options has the following structure:

type alias Options = 
    { enableHighAccuracy : Bool
    , timeout : Maybe Int
    , maximumAge : Maybe Int
    }

The documentation specifies these values are in milliseconds. I'm curious why this isn't implemented using a Time instead. Wouldn't it reduce mistakes to use an interface that encodes the unit as well as the value?

-- unitless integers
{ defaultOptions | maximumAge = Just 30000 }

-- Times
{ defaultOptions | maximumAge = Just (30 * Time.second) }

(moved from #9)

Update to elm 0.19

Are there plans to upgrade this package to 0.19 ? Or has it been renamed somewhere else ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.