Displaying multiple map markers in Google Maps API

前端 未结 2 1256
南笙
南笙 2021-01-23 21:04

working on some perl code in a .cgi file that loops through a hash list of IP addresses, then runs each IP address through a web service that returns that latitude and longitude

2条回答
  •  被撕碎了的回忆
    2021-01-23 21:27

    Obviously you need to save all the latitudes and longitudes, rather than just print them. I'd use 2 globals, outside your unless($result){

    my $lats = '';
    my $lons = '';
    ....
    $lats .= $latitude . ',';
    $lons .= $longitude . ',';
    

    (You might need a chop($lats); chop($lons) after the loop to remove the last comma) Then in your javascript section:

    // create two arrays from that lats and lons string using split()
    var latitudes = "$lats".split(',');
    var longitudes = "$lons".split(',');
    .....
    // create map code
    ....
    for(var i = 0; i < latitudes.lenght; i++){
        var latitude = latitudes[i];
        var longitude = longitudes[i];
       // Creating a marker and positioning it on the map
       var marker = new google.maps.Marker({
           position: new google.maps.LatLng(latitude,longitude),
           map: map
       });
    }
    

提交回复
热议问题