Skip to content Skip to sidebar Skip to footer

Parsing Coordinates In Json To Show On A Map?

I am trying to use google maps api to show path of a user using a polyline. I am getting the coordinates in json format from a rest api i created. The api is working correctly but

Solution 1:

try this way

<script>


    function initMap() {

    var username = "<%= session.getAttribute("Member").toString() %>";

    var flightPlanCoordinates = [];
      $(document).ready(function(){
           $.ajax({
               url: "http://127.0.0.1:8082/letstravel/location/"+username,
               dataType: "json",
                success: function(data) {
                    for(var i in data){
                        flightPlanCoordinates.push({ lat: data[i].latitude, lng: data[i].longitude });
                    } 
                        }
           });  
      });


      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 3,
        center: {lat: 0, lng: -180},
        mapTypeId: google.maps.MapTypeId.TERRAIN
      });


      var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
        geodesic: true,
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 2
      });

      flightPath.setMap(map);
    }
</script>

Post a Comment for "Parsing Coordinates In Json To Show On A Map?"