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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:47:11+00:00 2026-06-16T05:47:11+00:00

I am creating a phonegap application for android. I am not really familiar with

  • 0

I am creating a phonegap application for android. I am not really familiar with Javascript and have encountered a scenario where I have two functions, one which initialises a map called “map” and another which takes care of showing a list of markers which is being loaded from a database on the map.

However my question is how am I able to set the marker to appear on a map which is initiated in a different function?

EDIT
Here is some code:

function map() {
...
map = new google.maps.Map(document.getElementById("map"), mapOptions);
...
}


function markers() {
var MarkerType1 = new google.maps.MarkerImage("/android_asset/www/assets/markerType1.png",
new google.maps.Size(29.0, 48.0),
new google.maps.Point(0, 0),
new google.maps.Point(14.0, 24.0)
);

var MarkerType2 = new google.maps.MarkerImage("/android_asset/www/assets/markerType2.png",
new google.maps.Size(29.0, 48.0),
new google.maps.Point(0, 0),
new google.maps.Point(14.0, 24.0)
);

var geocoder = new google.maps.Geocoder();
var eventList = $('ul#eventList').empty();

var eventPoints = $.ajax({
    type: 'GET',
    url: 'http://www.somedomain.com/loadEvents.php?&jsoncallback=?',
    dataType: 'JSONp',
    timeout: 5000,
    success: function(data) {
        $.each(data, function(i,item){
            if (item.EventType == 1) {                  
                    new google.maps.Marker({
                        position: new google.maps.LatLng(item.latitude, item.longitude),
                        map: this.map,
                        icon: MarkerType1,
                        draggable:false
                    });                      

            } else if (item.EventType == 2) {
                new google.maps.Marker({
                    position: new google.maps.LatLng(item.latitude, item.longitude),
                    map: this.map,
                    icon: MarkerType2,
                    draggable:false
                });
            }
        }
    }
});

}

  • 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-16T05:47:12+00:00Added an answer on June 16, 2026 at 5:47 am

    This is a question of variable scope. Make sure the variable map is declared outside both of the functions.

    eg. :

    $(function() {
        var map;//outer variable is accessible within both functions.
    
        function createMap() {
            map = new google.maps.Map({
                ...
            });
        }
    
        function createMarkers() {
            $.ajax({
                ...
                success: function(data) {
                    $.each(data, function() {
                        var marker = new google.maps.Marker({
                            map: map,
                            ...
                        });
                    });
                }
            });
        }
    
        createMap();
        createMarkers();
    
    });
    

    In practice, you would only need to put the map/marker creation code inside functions if it needed to be called in response to some future event(s).

    If you want to create the map and its markers immediately, when page is loaded, then you can do so as follows :

    $(function() {
        var map = new google.maps.Map({
            ...
        });
    
        $.ajax({
            ...
            success: function(data) {
                $.each(data, function() {
                    var marker = new google.maps.Marker({
                        map: map,
                        ...
                    });
                });
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used Android phonegap application for creating dynamic list with label and corresponding
I am creating a PhoneGap application for iOS and Android. I have gotten Android
I am creating a Phonegap application for android using JQuery Mobile. I have a
I'm creating a phonegap application which involves backbone.js, underscore.js, and require.js I want to
I'm creating a game for the iPad using Phonegap, which means I'm using JavaScript/
I'm creating an native Android application by using PhoneGap and jQuery Mobile. When I
I have started to working with phoneGap application for android. I followed the steps
I'm working on creating an android application with PhoneGap. What I'm trying to do
I'm creating a Phonegap Android application, I've placed a Youtube Iframe inside a webview.
I'm creating a application for IOS with the phonegap environment. I'm noticing on one

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.