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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:41:57+00:00 2026-05-27T05:41:57+00:00

All, I have the following bit of code: function addPoints() { newpoints[0] = new

  • 0

All,
I have the following bit of code:

function addPoints() {

newpoints[0] = new Array(41.45998, 87.59643, icon0, 'Place', 'Content to open'); 

    for(var i = 0; i < newpoints.length; i++) {
       var point = new GPoint(newpoints[i][1],newpoints[i][0]);
       var popuphtml = newpoints[i][4] ;
       var marker = createMarker(point,newpoints[i][2],popuphtml);
       map.addOverlay(marker);
   }
}

There is other code around this to display the marker on my map. However this value is hardcoded. I have a PHP/mySQL database that has lat/long coordinates along with some other values. Say I have like three entries that I want to create markers for. How would I pass the addPoints function the lat/long that I got from my database so I can use it in this function correctly?

I updated my code to look like the following for the addPoints:

function addPoints(num, lat, long) {
newpoints[num] = new Array(lat, long, icon0, 'Place', 'Stuff name'); 
alert("The newpoints length is: "+newpoints.length);
for(var i = 1; i < newpoints.length; i++) {
    var point = new GPoint(newpoints[i][1],newpoints[i][0]);
    var popuphtml = newpoints[i][4] ;
    var marker = createMarker(point,newpoints[i][2],popuphtml);
    map.addOverlay(marker);
}
}

I call this function by doing this:

<script> 
    addPoints('<?php echo json_encode($num_coordinates); ?>','<?php echo json_encode($lat_coordinates); ?>', '<?php echo json_encode($long_coordinates); ?>');
</script>

It doesn’t work though. When I try not to pass it to javascript and just output the lat coordinates for example. I get the following output:

{"1":"40.59479899","2":"41.4599860"}

Which are the correct coordinates in my array. No markers get created though. Any ideas on what to do next or what I’m doing wrong?

  • 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-05-27T05:41:58+00:00Added an answer on May 27, 2026 at 5:41 am

    PHP executes on the server before getting sent to the the client. Therefor, if you can do things like this:

    newpoints[0] = new Array(<?php echo $lattitude;?>, <?php echo $longitude;?>, icon0, 'Place', 'Content to open');

    Where $lattitude and $longitude are values that you pulled out of you database with PHP.

    When this page is requested by the client, your php code executes, real values get plugged in where those php tags are making it look like the example you provided, and then it gets sent to the client.

    If you want to change these values using JS on the client, or fetch new ones from the server, let me know and I’ll add an example of that.

    EDIT:

    Okay, in light of your comments, it sounds like you’ve got a few options. Here’s one:

    When the user selects a category (restaurants, bars, etc) you pass that category as a url parameter and reload either the whole page, or just the map part of it (depends on your set up but might be worth investigating). Your link would look something like this:

    http://www.your-domain-here.com/maps.php?category=bars

    Maps.php is ready to catch the category using the $_GET array:

    $category = $_GET['category']; //'bars'

    Your php then grabs the appropriate location data from the database (I’ll leave that part to you) and sticks it in a variable that your JS-controlled map will be able to use:

    //JS in maps.php  -  you could add this var to the window object
    // if you have separated js files...
    var locationCoords = <?php echo json_encode($arrayOfCoordinatesFromDB);?>;
    

    When you page loads on the client machine, it now has an array of coordinates to use for the map ready to go in the locationCoords variable.

    Then, depending on which coordinates you need to display on the map, you pass them as arguments to your addPoints() using standard Javascript (nothing tricky here).

    That’s how I’d do it. Hope that helps!

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

Sidebar

Related Questions

All, Say I have the following bit of code: select: function(start, end, allDay) {
My problem is a little bit complex. I have the following code: $(document).ready(function() {
I have the following code to zip all the files and then save it
I have the following bit of HTML <div class=article>this is a div article content</div>
Afternoon all. Another hour, another question! I have the following bit of jquery up
I have the following code snippet. I'm trying to list all the files in
I have the following bit of code that reads data from the an Oracle
Using the following bit of code: function Node(){ .... function foo(request){ for (var name
I have the following bit of code. I'm trying to dynamically add drop-down options
I have the following code: $('a.uiPopup').hover(function () { $('.uiTip').show(); }, function () { $('.uiTip').remove();

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.