Preventing href until gelocation captured (callback help)

Denis

After a user clicks an image (html code) I want it to ask for geolocation and only href when captured. The issue is that the specialDisplyLocation method is not being called at all to set the variables. I'm thinking it's something with the way I'm using the callback.

latlng, lat and lng are global variables

Here's the current code:

function getForSpecial(callback) {
    callback (arguments[1]);
}

function getGeo (compid){

    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(specialDisplayLocation, displayError);
        window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
    }else{
        display(2,"Sorry - your browser doesn't support geolocation! " +
            "Use your postal code.");
    }
}

function specialDisplayLocation() {
    latlng = new google.maps.LatLng(
        parseFloat(position.coords.latitude),
        parseFloat(position.coords.longitude));
    lat = position.coords.latitude;
    lng = position.coords.longitude;
    alert("lat: "+lat);
}

Html:

<div class="ad_125x125" 
    onclick="getForSpecial(getGeo,<?php echo $output125[0][0]; ?>)">
    <img src="/ed/img/promos/125/<?php echo $output125[0][1]; ?>" />
</div>
Satpal

As you are calling specialDisplayLocation as success callback. I would suggest you to redirect in that method.

function specialDisplayLocation() {
    latlng = new google.maps.LatLng(
        parseFloat(position.coords.latitude),
            parseFloat(position.coords.longitude));
    lat = position.coords.latitude;
    lng = position.coords.longitude;
    alert("lat: "+lat);

    //Redirect
    window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
}

EDIT

Try this

function getForSpecial(callback) {
    callback (arguments[1]);
}

function getGeo (compid){

    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function(){
            specialDisplayLocation();
            window.location.href = "specials.php?cid="+compid+"&lat="+lat+"&lng="+lng;
        }, displayError);

    }else{
        display(2,"Sorry - your browser doesn't support geolocation! " +
            "Use your postal code.");
    }
}

function specialDisplayLocation() {
    latlng = new google.maps.LatLng(
        parseFloat(position.coords.latitude),
        parseFloat(position.coords.longitude));
    lat = position.coords.latitude;
    lng = position.coords.longitude;
    alert("lat: "+lat);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Preventing scroll to top in href="#" links

From Dev

Bash Help with Until Loop

From Dev

Bash Help with Until Loop

From Dev

Wait until callback

From Dev

Preventing execution until points are selected on matplotlib graph

From Dev

Need help preventing form submission if element is not checked

From Dev

href adds symbols to link preventing it from opening

From Dev

Preventing href to move to header after action

From Dev

Preventing A HREF redirect but still completing action?

From Dev

Preventing href in <a></a> from executing via Javascript

From Dev

Wait until a callback address is called

From Dev

callback function for location.href

From Dev

AngularJS: Preventing form submission until asyncronous validator is complete

From Dev

CSS: Preventing a property to affect on element until the end of transition

From Dev

Preventing a jQuery function from being executed until current one is finished

From Dev

Preventing deconstruction of anonymous variable defined in macro until end of scope

From Dev

preventing gmail from stripping href, target, and id attributes

From Dev

getting moving gelocation on bing maps

From Dev

Need help rewriting a foreach and do until loop

From Dev

Callback function not waiting until jQuery fadeOut() completed?

From Dev

Sequelize wait until loop finished with callback

From Dev

Wait until a callback ends to continue execution in Angular

From Dev

Is this a correct way to pause thread until callback?

From Dev

Pause execution of a method until callback is finished

From Dev

jquery animate callback not executing until final loop

From Dev

How to wait until Callback has data?

From Dev

Hold on callback function execution until promise is completed

From Dev

Is there any quality difference in image captured using camera.takePicture(shutter callback, jpeg callback) and setOneShotPreviewCallback

From Dev

window.location.href - help redirecting

Related Related

  1. 1

    Preventing scroll to top in href="#" links

  2. 2

    Bash Help with Until Loop

  3. 3

    Bash Help with Until Loop

  4. 4

    Wait until callback

  5. 5

    Preventing execution until points are selected on matplotlib graph

  6. 6

    Need help preventing form submission if element is not checked

  7. 7

    href adds symbols to link preventing it from opening

  8. 8

    Preventing href to move to header after action

  9. 9

    Preventing A HREF redirect but still completing action?

  10. 10

    Preventing href in <a></a> from executing via Javascript

  11. 11

    Wait until a callback address is called

  12. 12

    callback function for location.href

  13. 13

    AngularJS: Preventing form submission until asyncronous validator is complete

  14. 14

    CSS: Preventing a property to affect on element until the end of transition

  15. 15

    Preventing a jQuery function from being executed until current one is finished

  16. 16

    Preventing deconstruction of anonymous variable defined in macro until end of scope

  17. 17

    preventing gmail from stripping href, target, and id attributes

  18. 18

    getting moving gelocation on bing maps

  19. 19

    Need help rewriting a foreach and do until loop

  20. 20

    Callback function not waiting until jQuery fadeOut() completed?

  21. 21

    Sequelize wait until loop finished with callback

  22. 22

    Wait until a callback ends to continue execution in Angular

  23. 23

    Is this a correct way to pause thread until callback?

  24. 24

    Pause execution of a method until callback is finished

  25. 25

    jquery animate callback not executing until final loop

  26. 26

    How to wait until Callback has data?

  27. 27

    Hold on callback function execution until promise is completed

  28. 28

    Is there any quality difference in image captured using camera.takePicture(shutter callback, jpeg callback) and setOneShotPreviewCallback

  29. 29

    window.location.href - help redirecting

HotTag

Archive