GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Fire OS Developer Docs
  • Fire Tablets

This view

  • Original page
  • New address

GeezerVison is showing developer.amazon.com — Use Geolocation Data (Fire Tablets) | Fire Tablets

Amazon Developer
Alexa
Amazon Appstore
Ring
AWS
Documentation

Console

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases

Console

as

Fire OS Developer Docs
Home
Develop
Test
Publish
Monetize
Engage users
Device specifications
Resources
Fire Tablets

Collapse All | Expand All


  • << Fire OS Developer Docs
    • Get Started
      • Get Started with Fire Tablets
      • Set Up Your Development Environment for Fire Tablets
      • Create Your First Fire Tablet App
      • Connect to Fire Tablet through ADB
      • Get started with Amazon Stylus SDK
      • UX Specifications
      • User Agent Strings for Fire Tablets
      • Supported Android Intents
      • FAQs for Fire Tablets
    • Fire OS for Fire Tablets
      • Fire OS 8 for Fire Tablets
      • Fire OS 7 for Fire Tablets
      • Fire OS 6 for Fire Tablets
    • Android Apps
      • Screen Layout and Resolution
      • Device Orientation
      • Soft Key Bar
      • Button Size and Placement
      • Graphics Performance
      • Data Transfers and Mobile Networks
      • Launcher Icon Guidelines
      • App Installation Location
      • Advertising ID
      • Resources for International Locales
    • Test your Android Apps
      • Run Your App on a Fire Tablet
      • Test Without an Amazon Device
      • Take Screenshots on Fire Tablets
    • Web Apps
      • Get Started with Web Apps
      • Set up Development Environment
      • Best Practices for Developing Web Apps
      • Web App FAQs
      • Detect the Device Display Characteristics
      • Force the Device Orientation
      • Handle Device Orientation
      • Automatically Scale an Element to Fill the Screen
      • HTTP Caching
      • Protect Your Web App
      • Capture Media from Device Sensors
      • Use Geolocation Data
    • Test Your Web Apps
      • Install and Use the Amazon Web App Tester
      • Debug Your Web App
      • Use the Debug APK to Test Your App
    • HTML5 Hybrid Apps
      • HTML5 Hybrid Apps
      • Build and Test Your HTML5 Hybrid App
      • HTML5 Hybrid App FAQs
    • React Native for Fire Tablet
      • Get Started with React Native (Fire Tablets)
      • Supported React Native Libraries (Fire Tablets)
    • Accessibility
      • Assistive Technologies for Fire OS
      • Implement Accessibility in Fire OS
      • Accessibility Features
        • Implement Reading and Subscribing to AD/CC Settings

    Use Geolocation Data (Fire Tablets)

    Geolocation data is available to your app through JavaScript on devices that support the navigator.geolocation property. The W3C provides a Geolocation API Specification that describes how to access geolocation data.

    The Geolocation sample demonstrates how to access geolocation data. The code for this sample is located in <Amazon Apps & Games Services SDKs>/Web/Cookbook/Geolocation/. The Web App SDK can be downloaded from the SDK Download page.

    • Detect Whether Geolocation is Supported
    • Request Geolocation Data for the User's Current Position
    • Use the Geolocation Data
    • Request Permission to Use Geolocation Data

    Detect Whether Geolocation is Supported

    To detect whether geolocation is supported, check to see whether the navigator.geolocation property is present. If it is present, geolocation is supported.

    if (navigator.geolocation) {
      // geolocation is supported
    } else {
      // geolocation is not supported
    }
    

    Request Geolocation Data for the User's Current Position

    After you have verified that the navigator.geolocation property is present, you can request geolocation data for the user's current position by calling navigator.geolocation.getCurrentPosition() with a minimum of one and maximum of three arguments. The arguments, in order, are:

    1. (Required) A callback to a function that is called when the current location of the device is successfully determined.
    2. (Optional) A callback to a function that is called when an error occurs when attempting to determine the current location of the device.
    3. (Optional) An object encapsulating position-finding options.

    The position-finding options are as follows:

    • enableHighAccuracy (Boolean) provides a hint that the app would like to receive the best possible results. High-accuracy results might result in slower response times and/or increased power consumption. The user might deny this capability, or the device might not be able to provide results that are any more accurate than if this flag was set to false. The intent of this flag is to allow apps to inform the implementation that they do not require high-accuracy results so that the implementation can avoid using geolocation providers that consume a significant amount of power, such as GPS.
    • timeout (long) is the maximum number of milliseconds that can elapse between the call to getCurrentPosition() and when the corresponding success callback is invoked. If timeout milliseconds elapse and no other errors have occurred, the error callback is called with a timeout error code.
    • maximumAge (long) is the maximum number of milliseconds old a cached location can be and still be used. If maximumAge is set to zero, the implementation must immediately attempt to get new position data. Setting maximumAge to infinity means that cached data will always be returned, regardless of age.

    Here is an example call to getCurrentPosition() with a success callback, error callback, and options object defined. The implementation of the success callback is shown in the section called Using Geolocation Data. The implementation of the error callback is not shown.

    var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };
    
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPositionSuccessCallback, showPositionErrorCallback, options);
    } else {
      $("#location").text("Geolocation is not supported in this browser or context");
    }
    

    Use the Geolocation Data

    After you have requested geolocation data and the request is successfully processed, the success callback is called. The callback function receives a position object that contains a coordinates object and a timestamp. The coordinates object contains the following properties:

    • latitude specified in decimal degrees.
    • longitude specified in decimal degrees.
    • altitude is the height, in meters, of the position above the WGS84 ellipsoid. Might be null if the implementation cannot provide this information.
    • accuracy of latitude and longitude, specified in meters with a 95% confidence level.
    • altitudeAccuracy specified in meters with a 95% confidence level. Might be null if the implementation cannot provide altitude information.
    • heading is the device's direction of travel, specified in degrees such that 0° ≤ heading < 360°. Might be NaN if the device is stationary (i.e., speed is 0). Might be null if the implementation cannot provide heading information.
    • speed is the magnitude of the horizontal component of the device's current velocity, specified in meters per second. Might be null if the implementation cannot provide speed information.

    Here is an example success callback that uses the information in the position's coordinates object to display latitude, longitude, and accuracy information, as well as a link to a map where the latitude and longitude are embedded in the query string:

    function showPositionSuccessCallback(position) {
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
      var accuracy = position.coords.accuracy;
      $("#location").html("Latitude: " + latitude
                          + "<br/>Longitude: " + longitude
                          + "<br/>Accuracy: " + accuracy + " meters");
      $("#osm").html('<a href="http://www.openstreetmap.org/?lat=' + latitude
                     + '&lon=' + longitude + '&zoom=17&layers=M">Open Street Maps view</a>');
    }
    

    Request Permission to Use Geolocation Data

    When you submit your app to the Amazon Appstore, make sure you check the checkbox for Geolocation in the section called Web App Features on the App Information tab. This will add the appropriate permissions to the Android manifest. If you do not check the appropriate checkbox, the geolocation features of your app will not work.


    Last updated: Jun 09, 2022


    • Detect Whether Geolocation is Supported
    • Request Geolocation Data for the User's Current Position
    • Use the Geolocation Data
    • Request Permission to Use Geolocation Data
    Follow us:

    Resources

    • Appstore developer blog

    • Technical documentation

    • Amazon Developer Huddle

    Supported devices

    • Amazon Fire TV

    • Fire tablets

    Other services & APIs

    • Small Business Accelerator Program

    • Developer Promotions Console

    • Alexa for video publishers

    • Login with Amazon

    • Frustration-Free Setup

    • Amazon Incentives API

    • Amazon Merch on Demand

    • Amazon Music

    • Fire TV Partners

    Support

    • Appstore Developer Community

    • FAQs

    • Contact us

    Legal

    • Terms & agreements

    • Privacy Notice

    amazon_developer_logo

    © 2010-2026, Amazon.com, Inc. or its affiliates. All Rights Reserved.

    Terms

    Amazon Developer Blog

    Contact Us

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.