hi i am doing a project now i going to use ajax to retrieve coordinate from the json in html and pin the coordinate onto a point on the map using javascript but the problem is i am only able to use one point on the map can tell me what to add in ? or how should i change it with? p.s it will be nice if u can change the code from the below and show me how
function addSymbol() {
if (omap.map.getLayer("symbolLayer") == null) {
omap.map.addLayer(gLayer);
omap.map.infoWindow.resize(760, 425);
}
gLayer.clear();
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
if (window.ActiveXObject){
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes)
}catch(e){ }
}
}
else if (window.XMLHttpRequest)
return new XMLHttpRequest()
else
return false
}var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function(){
if (mygetrequest.readyState==4){
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
var books=eval("("+mygetrequest.responseText+")") //retrieve result as an JavaScript object
var rssentries=books.places
var output = ""
var xCoo = ""
var yCoo= ""
for (var i=0; i<rssentries.length; i++){
output += rssentries.name
xCoo += rssentries.x_coordinate
yCoo += rssentries.y_coordinate
}
document.getElementById("result").innerHTML = output
var stX = xCoo
var stY = yCoo
var pt = new esri.geometry.Point(stX, stY, omap.map.spatialReference);
var attr = { "PlaceName": " Singapore", "PlaceAddr": "addr" };
var strImage = "http://www.rw-designer.com/i/download48b.png";
var symbol = new esri.symbol.PictureMarkerSymbol(strImage, 25, 25);
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setContent();
var graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);
gLayer.add(graphic);
}
else{
alert("An error has occured making the request")
}
}
}
mygetrequest.open("GET", "HTMLPage3.htm", true)
mygetrequest.send(null);
}
dojo.addOnLoad(addSymbol);
this is HTMLPage3 which is json data
{ "places": [
{
"id": "1",
"name": "Chinese Swimming Club",
"x_coordinate": "35484.66533355533",
"y_coordinate": "31293.823929446196"
},
{
"id": "2",
"name": "Police Station",
"x_coordinate": "35951.524906914485",
"y_coordinate": "31862.739419191174"
},
{
"id": "3",
"name": " View",
"x_coordinate": "35580.593252799175",
"y_coordinate": "31579.825950310897"
}
]
}