javascript - spit string and set them to map as a marker -
i try create marker on map.
use bing map
have 2 string comma separate.
in 2 different variable.
var region = "pune,kolkata"; var activity = "cricket,one day";
i try java-script ajax:-
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title></title> <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3c"> </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> var region = 'pune,kolkata'; var cntry_code= 'in'; var activity = "cricket,one day" var map = null; function getmap() { map = new vemap('mymap'); map.loadmap(); $(document).ready(function(){ var array_region = region.split(','); var array_activtiy= activity.split(','); for(var item_region in array_region) (var item_activity in array_activtiy) { $.ajax({ url: "http://services.gisgraphy.com//geocoding/geocode?address="+array_region[item_region]+"&country="+cntry_code+"&format=json", async: false, datatype:'jsonp', success: function(data){ lat = data.result[0].lat; lng = data.result[0].lng; alert(lat); alert(lng); map.loadmap(new velatlong(lat,lng)); var pinpoint = map.getcenter(); shape = new veshape(veshapetype.pushpin, pinpoint); shape.settitle("activity name:- "); shape.setdescription(array_activtiy[item_activity]+","+array_region[item_region]); map.addshape(shape); } }); alert(array_region[item_region]); } }); } </script> </head> <body onload="getmap();"> <div style="width:630px; background-color: #e0e0e0; height: 500px; border: 1px solid black"> <div id='mymap' style="position:relative; width:600px; height:400px; margin-left:15px"></div> </div> </body> </html>
with try split string comma.
, pass ajax url.
, got lat , lng.
use lat , lng.
set place there activity.
work fine.
little problem add last place , last activity marker.
think problem in loop.
please 1 check out query.
thanks.
you should not use for(var item_region in array_region)
construct arrays. replace line like:
for (var item_region, = 0; < array_region.length; i++) item_region = array_region[i];
you need similar change on following line - left exercise
Comments
Post a Comment