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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:09:15+00:00 2026-06-04T23:09:15+00:00

I am new to JavaScript. Writing a script that uses GooogleMaps API Working OK.

  • 0

I am new to JavaScript.

Writing a script that uses GooogleMaps API

Working OK. Get Lat Lngs from Database, Make markers, put on Map.

Decided to move a function call up a level, (it was in the OnSuccess method of a PageMethod call). Stopped working.

Put in alerts to diagnose. Starts working.

Narrowed down to having alert at top of called function MakeLatLngs().

MakeLatLngs code appears to execute regardless of alert being present or commented out.
It is just that the map displays with alert statement in and doesn’t display with alert statement commented out.
The alert is just text and not using any variable. So I am at a loss to understand what is going on here.

The same thing is happening in the function that draws the map DrawMap(). I put an informative alert at the start of the function and the map draws. Leave it out and the map doesn’t.

Any clues as to what is going on would be appreciated?

The script is below.
Flow starts at function Initialise at bottom of script.
thanks

     var myPositions = [];
     var myRoutes = [];
     var myString = [];
     var myLatLngs = [];
     var myTitles = [];
     var NumPoints;
     var map;
     var poly;
     var RouteName;
     var myMarkers = [];
     var myMapCentre = new google.maps.LatLng(-41.2954168187213, 174.767133718655);
     function DrawMap() {
         alert("Generating Points for " + RouteName);// Need this to display
         var thisLatLng = myLatLngs[0];

         var myOptions = {
             zoom: 8,
             center: thisLatLng,
             mapTypeId: google.maps.MapTypeId.ROADMAP
         };

         map = new google.maps.Map(document.getElementById('map_canvas'),
        myOptions);

         MakeMarkers();
         RouteLine();
     }

     function OnSuccess1(response) {
         myPositions = new Array();

         myString = response;

         NumPoints = response.length;
         for (var i = 0; i < NumPoints; i++) {
             myPositions[i] = response[i];

         }
     }
     function OnError1(response) {
     }

     function Marker()
     {
     this.meterId=0;
     this.latLng="";
     }
     function OnSuccess(response) {
         myPositions = new Array();

         myString = response;

         NumPoints = response.length;
         alert("Numpoints is " + NumPoints);
         for (var i = 0; i < NumPoints; i++) {
             myPositions[i] = response[i];

         }
         alert("Exiting OnSuccess");
         //MakeLatLngs(); //ORIGINAL POSITION OF LATLNG CALL
         return true;
     }

     function setRoute() {
     RouteName = prompt(' What route?', '');

     }

     function OnError(error) {
         alert("In Error");
     }
     function RouteLine() {
         var polyOptions = {
             strokeColor: '#000000',
             strokeOpacity: 1.0,
             strokeWeight: 3
         }
         poly = new google.maps.Polyline(polyOptions);
         poly.setMap(map);
         var path = poly.getPath();
         for (var i = 0; i < NumPoints; i++) {
             path.push(myLatLngs[i]);
         }

     }

     function MakeLatLngs() {
         alert("You need me now " );//Got to have this to display OK when called from LoadData
         myLatLngs = new Array();
         for (var i = 0; i < NumPoints; i++) {

             var sMarker = myPositions[i];

             var SeqPos = sMarker.indexOf(";");
             var latLngPos = sMarker.indexOf(";", SeqPos + 1);
             var marker = sMarker.substring(0, latLngPos);
             //alert("Marker is " + marker);
             //var Seq = sMarker.substring(latLngPos + 1, SeqPos - latLngPos);
             myTitles[i] = marker;
             //alert("MeterId is " + marker);
             var sLatLng = sMarker.substring(latLngPos + 1)
             //alert("SLatLng is " + sLatLng);
             var pos = sLatLng.indexOf(",");
             //alert("pos is " + pos);
             var sLat = sLatLng.substring(0, pos);
             //alert("sLat is " + sLat);
             var sLng = sLatLng.substring(pos + 1, sLatLng.length - 1);
             //alert("sLng is " + sLng);
             var lat = parseFloat(sLat);
             var lng = parseFloat(sLng);


             //alert("Lat is " + lat + " Long is " + lng);
             if (!isNaN(lng) && !isNaN(lat) && lat != 0 && lng != 0 ) {
                 var latlng = new google.maps.LatLng(lat, lng);
                 myLatLngs[i] = latlng;
             }

         }
         alert("Exiting MakeLatLngs")

     }

     function MakeMarkers() {

         for (var i = 0; i < NumPoints; i++) {
             var sTitle = "MyValue " + i;
             var marker = new google.maps.Marker({
                 position: myLatLngs[i],
                 map: map,
                 title: myTitles[i]
             });
         }
     }

     function LoadData() {

         setRoute();//Get the desired route from the user
         PageMethods.GetMarkers(RouteName, OnSuccess, OnError);
         MakeLatLngs(); //Works here ONLY WHEN AN ALERT IS FIRST LINE in FUNCTION. Orginal call was at end of OnSuccess
         //PageMethods.GetRouteBoundaries(OnSuccess1, OnError1);
         return false;
     }

     function initialize() {

         LoadData();
         DrawMap();
     }

     google.maps.event.addDomListener(window, 'load', initialize);//yes you do need this with or without <body onload="initialise">
  • 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-04T23:09:17+00:00Added an answer on June 4, 2026 at 11:09 pm

    The reason is that your PageMethods.GetMarkers is asynchronous, so the data hasn’t loaded when you invoke DrawMap. I guess when you use the alert, it pauses execution long enough for the data to load. Put the DrawMap method inside the OnSuccess of the page method, and that should solve the problem.

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

Sidebar

Related Questions

How do I make new attribute for html5 tags? I'm writing Javascript code and
I am a bit new to Javascript. I am writing this dummy script to
So I'm pretty new to javascript...right now I'm just writing that dynamic logout button
Possible Duplicate: How can JavaScript make new page that contains more JavaScript? I tried
I have just started learning Jquery and am new to writing javascript (I am
im new to javascript and am intersted in creating a small o3d script: <!DOCTYPE
im new at javascript and i can get this slider to work but not
I am new to jQuery / AJAX. I have a page that uses colorbox
I'm writing a webpage that relies on an external javascript file (that I have
Background So I am writing an emotify script for my tumblr, so that when

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.