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 8418929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:27:52+00:00 2026-06-10T02:27:52+00:00

I am working with the jQuery mobile google maps example here, focusing on the

  • 0

I am working with the jQuery mobile google maps example here, focusing on the first “Basic Map Example”.

http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-mobile.html

I want to be able to dynamically add markers to the basic_map, but I am having some trouble. I’m new to jQuery mobile and JavaScript.

Here is my edited version of the basic-map example from the jQuery mobile UI website. If you save it in the jQuery mobile demos folder, then everything should render properly. I have added a button at the bottom of the map page and also the addMarkers function. When you load the page, the map shows up centered at the mobileDemo coordinates (-41, 87), which is close to chicago, but not quite there. When you click on the button, I want to update the map with another marker at the chicago point, but the screen goes blank.

This is just a mock example of what I really want to do. In my longer, more complicated program, I’m querying a database to find addresses that match the query, then I want to put those markers up on the map dynamically. What do I need to change about this source code to be able to plot the Chicago point (or other markers on the fly)?

<!doctype html>
<html lang="en">
   <head>
        <title>jQuery mobile with Google maps - Google maps jQuery plugin</title>
        <link type="text/css" rel="stylesheet" href="css/jquery-mobile-1.0/jquery.mobile.css" />
        <link type="text/css" rel="stylesheet" href="css/mobile.css" />
        <script type="text/javascript" src="js/modernizr-2.0.6/modernizr.min.js"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script> 
        <script type="text/javascript" src="js/jquery-1.7.1/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery-mobile-1.0/jquery.mobile.min.js"></script>
        <script type="text/javascript" src="js/jquery.ui-1.8.15/jquery.ui.autocomplete.min.js"></script>
        <script type="text/javascript" src="js/demo.js"></script>
        <script type="text/javascript" src="../ui/jquery.ui.map.js"></script>
        <script type="text/javascript" src="../ui/jquery.ui.map.services.js"></script>
        <script type="text/javascript" src="../ui/jquery.ui.map.extensions.js"></script>
        <script type="text/javascript">

            var mobileDemo = { 'center': '41,-87', 'zoom': 7 };
            var chicago = new google.maps.LatLng(41.850033,-87.6500523);
            var map 
            function addMarkers(){
                map = new google.maps.Map(document.getElementById('map_canvas'));
                var marker = new google.maps.Marker({
                    map: map,
                    position: chicago
                });
            }

            $('#basic_map').live('pageinit', function() {
                demo.add('basic_map', function() {
                    $('#map_canvas').gmap({'center': mobileDemo.center, 'zoom': mobileDemo.zoom, 'disableDefaultUI':true, 'callback': function() {
                        var self = this;
                        self.addMarker({'position': this.get('map').getCenter() }).click(function() {
                            self.openInfoWindow({ 'content': 'Hello World!' }, this);
                        });
                    }}); 
                }).load('basic_map');
            });

            $('#basic_map').live('pageshow', function() {
                demo.add('basic_map', function() { $('#map_canvas').gmap('refresh'); }).load('basic_map');
            });
        </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 data-role="content">
                <a href="#" data-role="button" data-theme="b" onclick="addMarkers()">Add Some More Markers</a>
            </div>
        </div>      
    </body>
</html>
  • 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-10T02:27:54+00:00Added an answer on June 10, 2026 at 2:27 am

    Please check the below example.

    In the first map load there isn’t any marker. When you click the button then a marker is dynamically added without a need for page or map refresh.

    <!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" src="http://jquery-ui-map.googlecode.com/svn/trunk/ui/min/jquery.ui.map.min.js"></script>
                <script type="text/javascript">
    
                    var chicago = new google.maps.LatLng(41.850033,-87.6500523),
                    mobileDemo = { 'center': '41,-87', 'zoom': 7 };
    
                    function initialize() {
                        $('#map_canvas').gmap({ 'center': mobileDemo.center, 'zoom': mobileDemo.zoom, 'disableDefaultUI':false });
                    }
    
                    $(document).on("pageinit", "#basic-map", function() {
                        initialize();
                    });
    
                    $(document).on('click', '.add-markers', function(e) {
                            e.preventDefault();
                            $('#map_canvas').gmap('addMarker', { 'position': chicago } );
                    });
                </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>
                        <a href="#" class="add-markers" data-role="button" data-theme="b">Add Some More Markers</a>
                    </div>
                </div>      
            </body>
        </html>
    

    The initial map:

    enter image description here

    The map after the button’s click:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with jQuery Mobile for the first time and I'm having trouble accomplishing
I'm trying to display a Google Map on a JQuery Mobile page, but am
I'm developing a jQuery Mobile app which really relie on Google Maps. Although I
I have a jqueryMobile app that uses google maps api and is working properly
I'm working with jquery mobile library... Couple of days a go...I ran into a
Okay I'm working in jQuery mobile, and I just put in a PHP script
I have been working with jQuery mobile 1.0.1. I have a page which drills
I am working on a jquery mobile app, where i want to display the
I am working on a JQuery Mobile application. Each of my .html files basically
I am working on a jQuery Mobile App. On one of the pages 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.