extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Made a Geolocation extension

Open samuellouf opened this issue 9 months ago • 22 comments

Hello, folks! I made a Geolocation extension. Enjoy!

samuellouf avatar Feb 19 '25 09:02 samuellouf

This is pretty simple, I will give it a review later today if I don't forget

yuri-kiss avatar Feb 19 '25 16:02 yuri-kiss

This is pretty simple, I will give it a review later today if I don't forget

Thanks!

samuellouf avatar Feb 20 '25 14:02 samuellouf

Okay, I'm just gonna add Geocoding Blocks. I'm giving up on that idea. I will probably do a separate "Geocoding" extension.

samuellouf avatar Feb 20 '25 15:02 samuellouf

Here ! It's finally done!

samuellouf avatar Feb 21 '25 08:02 samuellouf

I can't find any blocks to actually get my location, which is a pretty necessary feature for a geolocation extension.

huh didn't notice that, maybe we're missing something?

Brackets-Coder avatar Sep 15 '25 16:09 Brackets-Coder

I can't find any blocks to actually get my location, which is a pretty necessary feature for a geolocation extension.

it's an error with the extension. the block has the wrong menu so it points to one that doesn't exist (it should be coordinates) image

CST1229 avatar Sep 16 '25 12:09 CST1229

I can't find any blocks to actually get my location, which is a pretty necessary feature for a geolocation extension.

it's an error with the extension. the block has the wrong menu so it points to one that doesn't exist (it should be coordinates) image

Thanks, I didn't notice

Brackets-Coder avatar Sep 16 '25 13:09 Brackets-Coder

I can't find any blocks to actually get my location, which is a pretty necessary feature for a geolocation extension.

it's an error with the extension. the block has the wrong menu so it points to one that doesn't exist (it should be coordinates)

You are right.

samuellouf avatar Sep 17 '25 09:09 samuellouf

Dunno how I let that slip.

samuellouf avatar Sep 17 '25 09:09 samuellouf

Fixed it!!

samuellouf avatar Sep 17 '25 09:09 samuellouf

Fixed it!!

I'll check when I can

Brackets-Coder avatar Sep 17 '25 12:09 Brackets-Coder

I just made a few changes :

  • Changed the default timeout (bc I realised 5 seconds weren't enough)
  • Fixed the getCurrent function (the timeout and the accuracy weren't taken into account until this fix)

samuellouf avatar Sep 19 '25 12:09 samuellouf

Get longitude and latitude doesn't seem to work for me in Safari (the block says it's supported and it's not an API limitation), and in Firefox longitude is negative where for me it should be positive according to my Maps app.

Perhaps there's something wrong with your computer or your phone. (No offense) It works for me on both Google Chrome and Firefox on Windows 10, 11, and Linux Mint.

samuellouf avatar Sep 19 '25 13:09 samuellouf

@PPPDUD, could you check if the position the extension returns is valid?

samuellouf avatar Sep 19 '25 13:09 samuellouf

Get longitude and latitude doesn't seem to work for me in Safari (the block says it's supported and it's not an API limitation), and in Firefox longitude is negative where for me it should be positive according to my Maps app.

Perhaps there's something wrong with your computer or your phone. (No offense) It works for me on both Google Chrome and Firefox on Windows 10, 11, and Linux Mint.

It's not the computer, I'm on a modern Mac with the latest software version. It works in Firefox, not Safari- it's not a browser limitation because the extension says I support geolocation and Apple's MapJS kit wouldn't work without geolocation capabilities, so something about the get location reporter doesn't work in Safari.

Also, the longitude is still negative, where according to my maps app, it should be positive.

Brackets-Coder avatar Sep 19 '25 13:09 Brackets-Coder

Get longitude and latitude doesn't seem to work for me in Safari (the block says it's supported and it's not an API limitation), and in Firefox longitude is negative where for me it should be positive according to my Maps app.

Perhaps there's something wrong with your computer or your phone. (No offense) It works for me on both Google Chrome and Firefox on Windows 10, 11, and Linux Mint.

It's not the computer, I'm on a modern Mac with the latest software version. It works in Firefox, not Safari- it's not a browser limitation because the extension says I support geolocation and Apple's MapJS kit wouldn't work without geolocation capabilities, so something about the get location reporter doesn't work in Safari.

That's interesting. I don't get why it isn't working. It should work. Is the longitude still negative?

samuellouf avatar Sep 19 '25 13:09 samuellouf

Should I add a "when user moves" block? (It would be a hat, ofc) It would be paired with latitude, longitude, accuracy blocks. It seems to be easily doable.

samuellouf avatar Sep 19 '25 13:09 samuellouf

Get longitude and latitude doesn't seem to work for me in Safari (the block says it's supported and it's not an API limitation), and in Firefox longitude is negative where for me it should be positive according to my Maps app.

Perhaps there's something wrong with your computer or your phone. (No offense) It works for me on both Google Chrome and Firefox on Windows 10, 11, and Linux Mint.

It's not the computer, I'm on a modern Mac with the latest software version. It works in Firefox, not Safari- it's not a browser limitation because the extension says I support geolocation and Apple's MapJS kit wouldn't work without geolocation capabilities, so something about the get location reporter doesn't work in Safari.

That's interesting. I don't get why it isn't working. It should work. Is the longitude still negative?

Yes, but I'm not 180º on the other side of the world. A theory, I updated to the latest major macOS Tahoe release recently and it's a .0 version. I've discovered a few UI inconsistencies after the redesign so there may be potential functionality issues in the latest version, but it's very unlikely.

Brackets-Coder avatar Sep 19 '25 13:09 Brackets-Coder

Should I add a "when user moves" block? (It would be a hat, ofc) It would be paired with latitude, longitude, accuracy blocks. It seems to be easily doable.

Depends on whether users would use it and how performant it would be

Brackets-Coder avatar Sep 19 '25 13:09 Brackets-Coder

Hmm... it seems like I have location services disabled in settings and Firefox is attempting to override it, so it may be faulty. I'll test it later when I have time

Brackets-Coder avatar Sep 19 '25 13:09 Brackets-Coder

Should I add a "when user moves" block? (It would be a hat, ofc) It would be paired with latitude, longitude, accuracy blocks. It seems to be easily doable.

@samuellouf That is genius, please add that! You might want to add a way to enable or disable that block though, since it's probably gonna eat up time pretty easily (see @Brackets-Coder's comment).

PPPDUD avatar Sep 19 '25 14:09 PPPDUD

Should I add a "when user moves" block? (It would be a hat, ofc) It would be paired with latitude, longitude, accuracy blocks. It seems to be easily doable.

@samuellouf That is genius, please add that! You might want to add a way to enable or disable that block though, since it's probably gonna eat up time pretty easily (see @Brackets-Coder's comment).

Done !

I added some code that sends the event, gets the threads to which the event was sent, and returns the value in the get [WHAT] block.

    async getCurrent(args, util) {
      if (!(await this.isAllowed())) return "";
      var coordinates =
        util.thread._coordinates || (await getGeolocation(this.options));
        // read the coordinates in the thread if present OR get the current coordinates
      if (coordinates.success == true) {
        return coordinates[args.WHAT];
      } else {
        return "";
      }
    }

    async changePositionWatching(args) {
...
        this.watcherID = navigator.geolocation.watchPosition(
          (pos) => {
            var threads = Scratch.vm.runtime.startHats(
              "samuelloufgeolocation_onUserMove"
            ); // Trigger the hat
            for (var thread of threads) { // for each thread
              var coords = pos.toJSON().coords; // Turn the coordinates into JSON
              coords.success = true; // Add success
              // @ts-ignore
              thread._coordinates = coords; // Add the coordinates to the thread
            }
          },
          () => {},
          this.options
        );
...
    }

samuellouf avatar Sep 20 '25 12:09 samuellouf