4

hi i have a function that get information from xml data and print markers on google map my problem is that i want to create a path between one point to the other point this is the code that retrive the data
`

  $.ajax({
                type:"POST",
                url:"PipeServlet?op=1",
                dataType:"xml",
                success: function(xml){
                    // Parses the data from xml
                    var newLat, newLon, newDesc,newName;
                    $(xml).find("deal").each(function(){
                        newName = $(this).find("name").text();
                        newLat = $(this).find("lat").text();
                        newLon = $(this).find("lon").text();
                        newDesc = $(this).find("desc").text();
                        // Displaying the Coupons on the map
                        marker = new google.maps.Marker({
                            position: new google.maps.LatLng(newLat,newLon),
                            map: map,
                            title: newName,
                            html: newDesc,
                            animation: google.maps.Animation.DROP
                        });`

So i want to add the date i retrive to a list and draw a lines like in this code :

mapLine = new google.maps.Polyline({map : map,
                                        strokeColor   : '#ff0000',
                                        strokeOpacity : 0.6,
                                        strokeWeight  : 4,
                                        path:[new google.maps.LatLng(33.240547551860935,35.6153623373566),new google.maps.LatLng(33.240009149357576,35.61381738496402)]
                                       });`

I want the line path:[new google.maps.LatLng(33.240547551860935,35.6153623373566),new google.maps.LatLng(33.240009149357576,35.61381738496402)] will be create in dynamic way thanks for yours help

1 Answer 1

2

Build an array: var path = new Array();

and add your object at the end of it: path.push(position);

$.ajax({
            type:"POST",
            url:"PipeServlet?op=1",
            dataType:"xml",
            success: function(xml){
                // Parses the data from xml
                var newLat, newLon, newDesc,newName;
                var path = new Array();
                $(xml).find("deal").each(function(){
                    newName = $(this).find("name").text();
                    newLat = $(this).find("lat").text();
                    newLon = $(this).find("lon").text();
                    newDesc = $(this).find("desc").text();
                    var position = new google.maps.LatLng(newLat,newLon);
                    path.push(position);
                    // Displaying the Coupons on the map
                    marker = new google.maps.Marker({
                        position: position,
                        map: map,
                        title: newName,
                        html: newDesc,
                        animation: google.maps.Animation.DROP
                    });
                ...
                });
                mapLine = new google.maps.Polyline({map : map,
                                strokeColor   : '#ff0000',
                                strokeOpacity : 0.6,
                                strokeWeight  : 4,
                                path:path
                });
                ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.