Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7839271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:23:27+00:00 2026-06-02T15:23:27+00:00

I user Bing Maps Ajax v7 API to get user’s location from the example

  • 0

I user Bing Maps Ajax v7 API to get user’s location from the example here

Is it possible to wait until the callback is executed and until I get a longitude, latitude for the user’s position or an error if he/she does not allow to get the position?

    function test() {
          //Call GetMap() to get position
          GetMap();
          //Wait until callback is finished
         //Do something with user's location (result of the callback)

     }

     function GetMap()
     {

        // Set the map options
        var mapOptions = {credentials:"Bing Maps Key"};


        // Initialize the map
        var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);

        // Initialize the location provider
        var geoLocationProvider = new Microsoft.Maps.GeoLocationProvider(map);

        // Get the user's current location
        geoLocationProvider.getCurrentPosition({successCallback:displayCenter});

        //Execute some more code with user's location
     }

     function displayCenter(args)
     {
        // Display the user location when the geo location request returns
        alert("The user's location is " + args.center);
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:23:30+00:00Added an answer on June 2, 2026 at 3:23 pm

    In JavaScript, I don’t think you can explicitly suspend execution and wait for a callback to finish as noted here: jQuery: wait for function to complete to continue processing? If you have some logic that depends on the result of the get position callback, why not just invoke that logic as part of the callback? You shouldn’t need to explicitly wait for it. In regards to what you want to accomplish, is something like this what you are looking for?

    var map;
    function test() {
          //Call GetMap() to get position
          GetMap();
          //Wait until callback is finished
         //Do something with user's location (result of the callback)
    
     }
    
     function GetMap()
     {
    
        // Set the map options
        var mapOptions = {credentials:"Bing Maps Key"};
    
    
        // Initialize the map
        map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);
    
        // Initialize the location provider
        var geoLocationProvider = new Microsoft.Maps.GeoLocationProvider(map);
    
        // Get the user's current location
        geoLocationProvider.getCurrentPosition({successCallback:displayCenter},{errorCallback:onError});
     }
    
    function onPositionReady(position) {
        // Execute some more code with user's location
        // For Example...
        // Apply the position to the map
        var location = new Microsoft.Maps.Location(position.coords.latitude,
            position.coords.longitude);
        map.setView({ zoom: 18, center: location });
    
        // Add a pushpin to the map representing the current location
        var pin = new Microsoft.Maps.Pushpin(location);
        map.entities.push(pin);
    }
    
    function onError(err) {
        switch (err.code) {
            case 0:
                alert("Unknown error");
                break;
            case 1:
                alert("The user said no!");
                break;
            case 2:
                alert("Location data unavailable");
                break;
            case 3:
                alert("Location request timed out");
                break;
        }
    }
    

    Update:
    If you want to pass arguments into your callbacks, you can use function binding to override the this keyword inside your callback and pass arguments that way:

    For example, if set up myObject to contain your arguments, you can pass it like so:

     geoLocationProvider.getCurrentPosition({ successCallback: onPositionReady.bind(myObject) }, { errorCallback: onError });
    

    Then, you access myObject in your callback via the this keyword:

    function onPositionReady(position) {
        var myProperty = this.yourProperty;  // this now refers to myObject
        // Execute some more code with user's location
        // For Example...
        // Apply the position to the map
        var location = new Microsoft.Maps.Location(position.coords.latitude,
            position.coords.longitude);
        map.setView({ zoom: 18, center: location });
    
        // Add a pushpin to the map representing the current location
        var pin = new Microsoft.Maps.Pushpin(location);
        map.entities.push(pin);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the Zip-Code for current user location from Windows Phone 7.
How to let the end user draw shapes at runtime on bing maps (Virtual
I have a jQuery search script based on the Bing API. When a user
I'm attempting to use the Bing Maps REST API to query the addresses of
I need to extend the bing maps control to be more user MVVM friendly
How do I disable just the grab aspect of panning for bing maps AJAX
I am using Bing Maps with Ajax and I have about 80,000 locations to
I have a silverlight application that contains Bing map. I want when the user
I am integrating bing maps into a web page. I am calling the GetDirections()
I am using the Silverlight sdk for Bing Maps. I have my map, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.