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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:34:04+00:00 2026-06-03T08:34:04+00:00

I have a set of coordinates in a database that I want to be

  • 0

I have a set of coordinates in a database that I want to be used to add markers on a google map

I created the following code

var map;
function initialize() 
  {
    var latloncenter = new google.maps.LatLng(51,-1.4469157);
    var myOptions = 
    {
      zoom: 4,
      center: latloncenter,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  }; 

  <? while($row = mysql_fetch_assoc($result)){?>

      var lon = "<?php echo($row['Longitude']); ?>"; 
      var lat = "<?php echo($row['Latitude']); ?>"; 


     //alert_test(lat,lon);
     setmarker(lat,lon);

<? } ?>



function setmarker(lat,lon)
{

var latlongMarker = new google.maps.LatLng(lat,lon);

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

}

function alert_test(lat,lon)
{
    alert(lat +" "+ lon);
}

<body onload="initialize()"><div id="map_canvas"></div></body>

it’s loading the map, and I know the query from the database is working correctly, However I think I am doing something wrong in the setmarker() method…. anyone knows how to make it work?

  • 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-03T08:34:06+00:00Added an answer on June 3, 2026 at 8:34 am

    You have to put your PHP-setmarker loop inside initialize(). Please try it.

    I don’t know all the intricacies of JavaScript but I think it’s a good idea to write var only once in var lat, var lon (it gets repeated in the PHP loop). Well, the JS interpreters probably don’t care either way.

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

Sidebar

Related Questions

So...i have used a map in a project which needs coordinates to set markers
The following code works asynchronously. I only have it set up to convert a
Have set of coordinates that need to be separated into groups that are close
I have users stored in a database that has latitude and longitude set on
I've created a database using the store locator tutorial on Google Code, which specifies
How can I input a set of coordinates and have Google maps show a
I have a ASP.net MVC application that gets marker coordinates from a database (I
So I have a function that gets some coordinates from a sql database and
If I have the following graph and I set the position coordinates of nodes
I have a set of (x,y) coordinates that describe the trajectory of an object.

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.