senters Posted July 22, 2012 Report Share Posted July 22, 2012 (edited) Patreiz ir šāds json formāts: {"longitude":25.63591,"latitude":56.896629} {"longitude":25.63591,"latitude":56.896629} {"longitude":25.63591,"latitude":56.896629} Vajadzīgs šādā formātā: "cities":[{latitude":34.647995,"longitude":-86.738549}, {latitude":34.647995,"longitude":-86.738549}, {...}, {...} ] PHP fails, kurā saģenerē no DB visus notikumus: $sql = mysql_query(" SELECT ... "); while($event = mysql_fetch_assoc($sql)) { $cities = array ( 'longitude' => $event['lng'], 'latitude' => $event['lat'] ); echo json_encode($cities); } Tālākais jau šo saformatēto masīvu savākt .js failā ar $.getJSON(), kur savāktos datus izkaisīs pa karti ar google maps api + MarkerClusterer + InfoWindow fīčām. Līdzīgs piemērs - http://stackoverflow.com/questions/7366861/plotting-latlng-coordinates-from-json-array-on-google-map-the-markers-all-st Edited July 22, 2012 by senters Quote Link to comment Share on other sites More sharing options...
codez Posted July 22, 2012 Report Share Posted July 22, 2012 http://codepad.org/WpHdsCzK $events=array( array("lat"=>12.234,"lng"=>32.454), array("lat"=>13.234,"lng"=>33.454), array("lat"=>14.234,"lng"=>34.454), ); $res=array(); $res['cities']=array(); foreach($events as $event){ array_push($res['cities'],array( "latitude"=>$event['lat'], "longitude"=>$event['lng'] )); } echo json_encode($res); Quote Link to comment Share on other sites More sharing options...
senters Posted July 22, 2012 Author Report Share Posted July 22, 2012 codez, pa pirmo! ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.