Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

problem with to addlister event google maps in same html file

$
0
0

I try to make two actionlistener one when the mouse over a marker show a infowindows and the other is for get when click on a market the lat and long and make an AJAX request
the two lister code is this mouseover

 google.maps.event.addListener(marker, 'mouseover', 
                function(event)
                {
                    map.panTo(event.latLng);
                    map.setZoom(17);
                    infoWindows[this.infoWindowIndex].open(map, this);
                }
            );

and code click event

google.maps.event.addListener(marker, 'click',function () {    
            var latitude = this.position.lat();
        var longitude = this.position.lng();
        var dataString = 'latStart='+ latPos + '&longStart='+ longPos + '&latend='+ latitude + '&longEnd='+ longitude;
            $.ajax({
                type: "POST",
                url: "routing.php",
                data: dataString,
                cache: false,
                success: function(result){      
               var jsonAr=JSON.parse(result);

map.data.setStyle({
fillColor: ‘red’,
strokeColor: ‘blue’,
fillOpacity: 1.5,
strokeWeight: 2
});

        map.data.addGeoJson(jsonAr);
                                }
                    });

                });

if put an alert inside the event click is show me the cords , the problem is not send the dataString in routing.php to return an array and draw a line in the map.
the php code is

     $latSta=substr($_POST['latStart'],0,10);
     $lngSta=substr($_POST['longStart'],0,10);
     $latEnd=substr($_POST['latEnd'],0,10);
     $lngEnd=substr($_POST['longEnd'],0,10);     
     $json_response = array();
     $json_response=array('type'    =>'FeatureCollection',
                        'features'=>array());

        //connect to db and make sql queries and return as json array the geome with cost

while ($row = pg_fetch_array($resultRouting,null, PGSQL_ASSOC)) {

        $json_response['features'][]
          = array('type'=>'Feature',
                  'properties'=>array('gid' => $row['gid'],
                                      'cost'=> $row['cost']
                                     ),
                  'geometry'=>json_decode($row['geom'], true)
                );
    }

    echo $json_response;

    pg_close($db);

Viewing all articles
Browse latest Browse all 148

Latest Images

Trending Articles



Latest Images