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

  • SEARCH
  • Home
  • 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 8490653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:11:20+00:00 2026-06-10T22:11:20+00:00

I am making a store locator app for mobile devices. A DB query runs

  • 0

I am making a store locator app for mobile devices. A DB query runs and gets distances and lan, lat values etc and shows the nearest stores on a page.

Then the user has the ability to click “view on map” to view the store and the current location on a google map. Heres main part of the code which is from the ajax() success callback:

                success: function(result){

                var rowCount = result.name.length;
                if(rowCount <= 0){
                    $('span.locatorResults').html("There were no stores found within your specified radius.");
                }else{

                    $( '#storeLocatorMapDisplay' ).live( 'pageshow',function(event){
                        initializeMapAll(); //This initialise SHOULD be called while the map_canvas div is in the DOM. This is why we have to do hacky workaround of resizing etc.. 
                    });

                    $('span.locatorResults').html("There are " + rowCount + " results within a " + result.radius + " mile radius of your current location:<br /><br />");

                    for (var i = 0; i < rowCount; i++) {

                        var storelatlng = new google.maps.LatLng(
                            parseFloat(result.storeLat[i]),
                            parseFloat(result.storeLon[i])
                        );
                        $( '#storeLocatorMapDisplay' ).live( 'pageshow',function(event){
                            createMarkerAll(storelatlng, result.name[i], result.address[i]);
                        });
                    }
                    $( '#storeLocatorMapDisplay' ).live( 'pageshow',function(event){
                        createMarkerCurrentLocation(currentlatlng);
                    });
                }                   
            }

My problem was, I was getting lots of grey padding around the map area and I read the its because the map was getting initialised BEFORE the map_canvas div is loaded into the DOM.

So I decided to initialise the map AND the markers when the map page was loaded, but this requires a lot of .live(‘pageshow’) events.

My question is… is there an easier way to initialise the map before creating the markers and before the map canvas is loaded into the DOM??? Bearing in mind that the markers (as far as i know) have to ge generated in the success callback from the ajax request.

Thanks for your time 🙂

  • 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-10T22:11:21+00:00Added an answer on June 10, 2026 at 10:11 pm

    The following example works exactly as you want. The markers are created inside the AJAX success function. For testing reasons I created a cityList array with the latitudes, longitutes. This cityList array should be removed and the data should be retrieved from the AJAX response data.

    <!doctype html>
    <html lang="en">
       <head>
            <title>jQuery mobile with Google maps - Google maps jQuery plugin</title>
            <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
            <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
            <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
            <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"> </script>
            <script type="text/javascript">
    
                var demoCenter = new google.maps.LatLng(41,-87),
                    map;
    
                function initialize()
                {
                    map = new google.maps.Map(document.getElementById('map_canvas'), {
                       zoom: 7,
                       center: demoCenter,
                       mapTypeId: google.maps.MapTypeId.ROADMAP
                     });
                }
    
                function addMarkers()
                {
                    // perform your AJAX here. In this example the markers are loaded through the cityList array
                    $.ajax({
                        type:'post',
                        url:'test.html',
                        data:'',
                        success:function(data)
                        {
    
                            // imagine that the data in this list
                            // will be retrieved from the AJAX response
                            // i used the cityList array just for testing
                            var cityList = [
                                    ['Chicago', 41.850033, -87.6500523, 1],
                                    ['Illinois', 40.797177,-89.406738, 2]
                                ],
                                marker,
                                i,
                                infowindow = new google.maps.InfoWindow();
    
                            for (i = 0; i < cityList.length; i++) 
                            {  
                                marker = new google.maps.Marker({
                                    position: new google.maps.LatLng(cityList[i][1], cityList[i][2]),
                                    map: map,
                                    title: cityList[i][0]
                                });
    
                                google.maps.event.addListener(marker, 'click', (function(marker, i) {
                                    return function() {
                                        infowindow.setContent(cityList[i][0]);
                                        infowindow.open(map, marker);
                                    }
                                })(marker, i));
                            }
                        }
                    });
                }
    
                $(document).on("pageinit", "#basic-map", function() {
                    initialize();
                    addMarkers();
                });
    
            </script>
        </head>
        <body>
            <div id="basic-map" data-role="page">
                <div data-role="header">
                    <h1><a data-ajax="false" href="/">jQuery mobile with Google maps v3</a> examples</h1>
                    <a data-rel="back">Back</a>
                </div>
                <div data-role="content">   
                    <div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
                        <div id="map_canvas" style="height:350px;"></div>
                    </div>
                </div>
            </div>      
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an EmployeeStore that will store names, dob, id, email address etc...
I'm making an app that uses a SQLite database to store data. Sometimes my
I've gone down the path of making my magento store mobile friendly. At first
I am making a web app which needs to store a user's email and
I am making an app where there is a requirement to store ASCII art
I am making a class to open a webpage and store the href values
I am making store locator application. In my application i am showing nearest store
I'm making a Windows Store app in C# and I have a normal TextBlock
I am making an application to Store textfield values to database.After entering values when
I'm making a simple app than needs to store a simple structure of data.

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.