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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:48:10+00:00 2026-06-17T04:48:10+00:00

I have a MySQL database from which I fetch data to show a marker

  • 0

I have a MySQL database from which I fetch data to show a marker on my Google map. I would want to show n markers but I don’t know how to implement for-loop so that

var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!',
});

would repeat n-times. I’ve tried adding for loop function but I can’t get it right. I’m only starting to learn JavaScript.

Here’s the rest of the code: http://jsfiddle.net/Wkn9v/7/

Thank you!

  • 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-17T04:48:11+00:00Added an answer on June 17, 2026 at 4:48 am

    I modified your code so the logic is performed in the initialize function, because otherwise the loop wasn’t executing properly. There was some other stuff in the wrong places too. This works:

    jQuery(function ($) {
      var map_canvas = document.getElementById('map_canvas');
    
      $.getJSON('http://www.wawhost.com/appProject/fetchmarker.php?callback=?', function (data) {
        initialize(data);
      });
    
      function initialize(data) {
        var myLatlng = new google.maps.LatLng(-25.363882, 131.044922),
          mapOptions = {
            zoom: 4,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          },
          map = new google.maps.Map(map_canvas, mapOptions),
          pos, lat, lng, latlang, marker;
    
        for (var i = 0, l = data.length; i < l; i++) {
          localStorage.loc = data[i].location;
    
          pos = localStorage.loc.split(",");
          lat = parseFloat(pos[0]);
          lng = parseFloat(pos[1]);
    
          latlang = new google.maps.LatLng(lat, lng);
    
          marker = new google.maps.Marker({
            position: latlang,
            map: map,
            title: 'Hello World!' // <<< Keep in mind that trailing , that was here is unnecessary
          });
        }
      }
    
    });
    

    http://jsfiddle.net/userdude/Wkn9v/13/

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

Sidebar

Related Questions

Hi i have a small query which takes data from one mysql database and
I have function which selects data from MySQL database: function get_articles( $id ){ global
i have a mysql database from which i require an rss feed of its
I have a simple php page that displays data from a mysql database. I
I have been tasked with porting data from a MongoDB database to a MySQL
I have an old mysql code which I want to convert into PHP data
I have a backup from a WAMP server MYSQL database from home and I
I have a MySQL database that I am keeping temperature readings from several different
I have the following task: there are a simple table from mysql database: <html>
I have three mysql table from same database Db1. Three tables have following columns.

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.