Description
This adds three simple functions to GM that allow you to get the user's current location. The location will be more accurate on devices with a GPS, like mobile phones. It will still work on computers, but may be less accurate. It uses the JavaScript GeoLocation features. Since these are asynchronous, there cannot be one function to simply get the user's location. You must first request the location and then check back to get it.
To use this, run "reqLocation()" to request the user's location. Then check (probably in the step event) if "getLongitude()" and "getLatitude()" return something other than zero. If they both return zero, the user's location is still not available. Once the location is available, they will return the user's location. Realize that if the user has denied access, they will always return zero.
I believe the GeoLocation features in JavaScript can detect if the user has denied access, and plan to update this as I learn more about it (and JavaScript itself). I realize that this, in its current state, is extremely simple. It is the first extension I have ever made (actually, the first thing I have ever written in Javascript), so please give me any suggestions. I would appreciate the help. I was just so happy that it worked I wanted to share it with someone! I plan to add more features, as I see that you can also get the user's altitude, as well as the accuracy of the GPS in the device, and other things. I plan to add functions for them all. As of now, it just does locations.
About the security of this, because some people may be paranoid about Game Maker games knowing their location. Browsers are required to ask the user before returning any GeoLocation data, so there is no way to track them without their knowledge. If you don't want your location known to a game, you can simply deny access and the game will not be able to get it. Read more about the security of JavaScript's GeoLocation API here.
More features to come, please reply with any comments or suggestions!
Downloads
[1.0] Download Here (.gex)
Functions
- reqLocation() - Requests the user's location. Returns 0 if the browser does not support geolocation. Returns 1 otherwise (even if the user denies access).
- getLongitude() - Returns the longitude coordinate. Can only be used after you have run reqLocation(). This will return 0 if the location has not yet been returned. It is not instant!
- getLatitude() - Returns the latitude coordinate. Can only be used after you have run reqLocation(). This will return 0 if the location has not yet been returned. It is not instant!
Compatible Browsers and Devices
Browsers
- Internet Explorer 9.0+
- Chome 5.0+
- Safari 5.0+
- Firefox 3.5+
- Opera 10.60+
- Android 2.0+
- iPhone 3.0+
- Opera Mobile 10.1+
- Symbian (S60 3rd & 5th generation)
- Blackberry OS 6
- Maemo
Examples and Demos
Game Maker Simple GPS Demo
This example is an extremely simple demonstration of what GeoLocation can do. It will display your latitude and longitude coordinates on the screen. When you first run the example, you will be asked whether or not you want to allow the website to use your location. If you deny the website access, you will see "ERROR" for the coordinates. You can see it in action by clicking "See it" and you can download the heavily commented example as a .gmz by clicking "Get it".
See It
Get It



Find content
Not Telling

