It is possible to get my current location Google maps with JavaScript?

Community Beginner ,
Nov 08, 2017

Copy link to clipboard

Copied

I found this code on web... But I don't know if this works...

var map = new google.maps.Map(document.getElementById('map'), {

    center: {lat: -34.397, lng: 150.644},

    zoom: 6

});

var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.

if (navigator.geolocation) {

    navigator.geolocation.getCurrentPosition(function(position) {

        var pos = {

            lat: position.coords.latitude,

            lng: position.coords.longitude

        };

        infoWindow.setPosition(pos);

        infoWindow.setContent('Location found.');

        map.setCenter(pos);

    }, function() {

        handleLocationError(true, infoWindow, map.getCenter());

    });

} else {

    // Browser doesn't support Geolocation

    handleLocationError(false, infoWindow, map.getCenter());

}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {

    infoWindow.setPosition(pos);

    infoWindow.setContent(browserHasGeolocation ?

                          'Error: The Geolocation service failed.' :

                          'Error: Your browser doesn\'t support geolocation.');

}

TOPICS
Acrobat SDK and JavaScript

Views

267

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

It is possible to get my current location Google maps with JavaScript?

Community Beginner ,
Nov 08, 2017

Copy link to clipboard

Copied

I found this code on web... But I don't know if this works...

var map = new google.maps.Map(document.getElementById('map'), {

    center: {lat: -34.397, lng: 150.644},

    zoom: 6

});

var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.

if (navigator.geolocation) {

    navigator.geolocation.getCurrentPosition(function(position) {

        var pos = {

            lat: position.coords.latitude,

            lng: position.coords.longitude

        };

        infoWindow.setPosition(pos);

        infoWindow.setContent('Location found.');

        map.setCenter(pos);

    }, function() {

        handleLocationError(true, infoWindow, map.getCenter());

    });

} else {

    // Browser doesn't support Geolocation

    handleLocationError(false, infoWindow, map.getCenter());

}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {

    infoWindow.setPosition(pos);

    infoWindow.setContent(browserHasGeolocation ?

                          'Error: The Geolocation service failed.' :

                          'Error: Your browser doesn\'t support geolocation.');

}

TOPICS
Acrobat SDK and JavaScript

Views

268

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 08, 2017 0
Most Valuable Participant ,
Nov 08, 2017

Copy link to clipboard

Copied

This forum is about JS in PDF files, not web-pages...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Community Beginner ,
Nov 08, 2017

Copy link to clipboard

Copied

yes I now! It is possible to "translate" this code to PDF JavaScript? And take my current location?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Most Valuable Participant ,
Nov 08, 2017

Copy link to clipboard

Copied

You can access external services using SOAP or even HTTP requests, but I don't see how you could use that to get your current location. Maybe through the IP address? But even then it's not going to be accurate.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0
Most Valuable Participant ,
Nov 08, 2017

Copy link to clipboard

Copied

This code relies on a geolocation feature of the JavaScript host. The Acrobat Javascript host has no such feature and is never likely to, especially in the m

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2017 0