Displaying multiple map markers in Google Maps API

前端 未结 2 1254
南笙
南笙 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:22

    Fixed it and have everything working now. The problem was that the $latitude and $longitude variables where still being assigned a bunch of extra text that was not needed. Now it is just assigned the value.

    my $latitude = $result->valueof('//LATITUDE');
    my $longitude = $result->valueof('//LONGITUDE');
    
    0 讨论(0)
  • 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
       });
    }
    
    0 讨论(0)
提交回复
热议问题