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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:05:30+00:00 2026-05-24T03:05:30+00:00

I would like to display multiple markers (up to 20 at least) on the

  • 0

I would like to display multiple markers (up to 20 at least) on the Google maps via Javascript. The data which comes in an array is in PHP.

Upon running the code, the Google map only plots the last co-ordinates in the array. Can you guys enlighten me why? Following are the codes (Sorry if this is albeit messy as i’m a novice. thanks for any help in advance):

$link ="http://network-tools.com/default.asp?prog=trace&host="."$ip_address";
$link_traceroute ="http://api.ipinfodb.com/v3/ip-city/?key=a15e8640c34837e4d402df55d7fd5e059e50d0d407d285a7a3b2ccbf85e1a234&ip=";

$response = file_get_contents("$link", false, $context);

$pieces_traceroute = strchr ($response, "$ip_address is from");
$split_pieces_traceroute = str_replace("Trace","$$$",$pieces_traceroute);
$better_pieces_traceroute =(explode("$$$",$split_pieces_traceroute));

$raw_data = strip_tags($better_pieces_traceroute[1]);
$split_data = (explode(" ",$raw_data));

for ($i=0; $i<count($split_data);$i++)
{

$checker= valid_ip($split_data[$i]);

    if ($checker != null){
    $response_traceroute = file_get_contents("$link_traceroute"."$split_data[$i]", false, $context);
    $pieces_traceroute = (explode(";",$response_traceroute));
    $Cord1 = $pieces_traceroute[8];
    $Cord2 = $pieces_traceroute[9];
    echo $Cord1.nl2br("\n");
    echo $Cord2.nl2br("\n");
    ?>

    </style>
<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
  function initialize() {
    var myLatlng = new google.maps.LatLng(<?php echo $Cord1;?>, <?php echo $Cord2;?>);
     var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
  }
 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

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

  // To add the marker to the map, call setMap();
  marker.setMap(map); 
  }
  • 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-24T03:05:31+00:00Added an answer on May 24, 2026 at 3:05 am

    You doesn’t need to loop the full js part (including <script> initialize). You get only the last value because of that. Try something like this instead…

    // Assume we have $locations variable which hold array data
    <script>
    function initialize() {
        var centerMap = <?php echo json_encode($locations[0]) ?>;
        var locations = <?php echo json_encode($locations) ?>;
        var centerLatlng = new google.maps.LatLng(centerMap[0], centerMap[1]);
        var map = new google.maps.Map(document.getElementById("map_canvas"), {
            zoom: 4,
            center: centerLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
        });
    
        var marker, i;
    
        for (i = 0; i < locations.length; i++) {  
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                map: map
            });
        }
    }
    </script> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to display multiple colors (and potentially shapes and sizes) of data
In MediaWiki, we would like to display tables of contents (from multiple pages) on
I would like to validate both single field and multiple field data from a
I would like to display 100000 records on browser / multiple pages with minimal
I would like to display a large number of results without multiple pages to
i am new programmer in android application i would like display multiple notifications one
I have a XML which has multiple records. I would like to populate those
I have a GridView with multiple columns. I would like to display a ContextMenu
I would like to display a gallery of photos and how many times each
I would like to display a loading bar before the entire page is loaded.

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.