u cant replace method parameter's signature with a string and expect it to run dynamically.
and also, dont expect a string to run as a JS statement.
ofcourse, eval() can run them dynamically, but it has its limitations.
use JS statements directly:
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(1, 103.849), 5);
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));
map.setUIToDefault();
u cant replace method parameter's signature with a string and expect it to run dynamically.
and also, dont expect a string to run as a JS statement.
ofcourse, eval() can run them dynamically, but it has its limitations.
use JS statements directly:
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(1, 103.849), 5);
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));
map.setUIToDefault();
Let me clear you both that why i am using dynamic variable and why i am not continueing whith my working code...
actually i want to make it dynamic...the existing one is for one record to display on map.i want to diplay all points on map...the lat,lon are coming dynamically from database so want to pass it dynamically...i have c# code in working but now i want to implement
it in jquery
The Issue is how to use this location variable in above code function.like i tried this...you people only correct me in this function
function initialize() {
if (GBrowserIsCompatible()) {
var center1 = "1";
var center2 = "103.849";
var center = center1 + "," + center2;
var Locations = "map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));map.addOverlay(new ELabel(new GLatLng(1, 103.850), 2, 'style11'));map.addOverlay(new ELabel(new GLatLng(1, 103.860), 3, 'style11'));";
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(center), 5);//Note:center variable explained above,now it equal to 1,103.849
//here i want to use location variable instead.is this correct?
+Locations+
map.setUIToDefault();
}
}
shafiqkr
Member
454 Points
372 Posts
JavaScript Concatenation issue
Apr 30, 2012 09:28 AM|LINK
Hi i am using variable values in a function in Js but do not work...
this is working and i want like this
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(1, 103.849), 5);
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));
map.setUIToDefault();
}
}
the above function working fine....now i want to use parameters/var which do not work
function initialize() {
if (GBrowserIsCompatible()) {
var center1 = "1";
var center2 = "103.849";
var center = center1 + center2;
var Locations = "map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));";
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(center), 5);
+Locations +
map.setUIToDefault();
}
}
now this do not work...can any body help me?how i use these variables here?
niksv
Contributor
5925 Points
1115 Posts
Re: JavaScript Concatenation issue
Apr 30, 2012 11:40 AM|LINK
I do not understand y would you want to do like that when you already have a working code. Still you should try javascript "eval()" function.
function test() { var msgbox = "alert('hello')"; eval(msgbox); }For more details see this: http://www.w3schools.com/jsref/jsref_eval.ASP
raju dasa
Star
14392 Points
2447 Posts
Re: JavaScript Concatenation issue
Apr 30, 2012 11:46 AM|LINK
Hi,
u cant replace method parameter's signature with a string and expect it to run dynamically.
and also, dont expect a string to run as a JS statement.
ofcourse, eval() can run them dynamically, but it has its limitations.
use JS statements directly:
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(1, 103.849), 5);
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));
map.setUIToDefault();
rajudasa.blogspot.com || blog@opera
shafiqkr
Member
454 Points
372 Posts
Re: JavaScript Concatenation issue
Apr 30, 2012 12:17 PM|LINK
Let me clear you both that why i am using dynamic variable and why i am not continueing whith my working code...
actually i want to make it dynamic...the existing one is for one record to display on map.i want to diplay all points on map...the lat,lon are coming dynamically from database so want to pass it dynamically...i have c# code in working but now i want to implement it in jquery
here is working c# code
string center1 = lstAd[0].Lat.ToString();
string center2 = lstAd[0].Lon.ToString();
center = center1 + "," + center2;
foreach (vwsearchQryResult cmp in lstAd)
{
string Latitude = cmp.Lat.ToString();
string Longitude = cmp.Lon.ToString();
Locations += @"map.addOverlay(new ELabel(new GLatLng(" + Latitude + "," + Longitude + ")," + count + "," + "'style11'" + " ));";
count = count + 1;
}
js.Text = @"<script type='text/javascript'>
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(" + center + @"), 10);
" + Locations + @"
//map.addControl(new GLargeMapControl());
map.setUIToDefault();
}
}
</script> ";
A1ien51
All-Star
29935 Points
5821 Posts
Re: JavaScript Concatenation issue
Apr 30, 2012 02:31 PM|LINK
Let us look at the code
What do you expect it to return? 104.849?
You are adding two strings together, not numbers. The quotes make them strings! So center's value is "103.8491".
Either make them numbers [drop the quotes]
or use parseFloat when adding them
Eric
shafiqkr
Member
454 Points
372 Posts
Re: JavaScript Concatenation issue
May 01, 2012 05:39 AM|LINK
No Never....if you look at my code,this is to set center and in this line
map.setCenter(new GLatLng(1, 103.849), 5);
i resolved this line here
1, 103.849 is equel to var center1 = "1"; and var center2 = "103.849";
var center = center1 + "," + center2;
now that line becomes
map.setCenter(new GLatLng(center), 5);
Till this line of code all is working well....i can see map.
Now i want to pass variable to map.addOverlay dynamically.
look here this is working well for static
now my whole working static function is like this
function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById('map_canvas')); map.setCenter(new GLatLng(center), 5);//Note:center variable explained above,now it equal to 1,103.849 map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11')); map.addOverlay(new ELabel(new GLatLng(1, 103.850), 2, 'style11')); map.addOverlay(new ELabel(new GLatLng(1, 103.860), 3, 'style11')); map.setUIToDefault(); } }Now i want to use these three lines dynamically so that lat,lon comes from table at run time.if i define a variable for these three lines here like
The Issue is how to use this location variable in above code function.like i tried this...you people only correct me in this function
function initialize() { if (GBrowserIsCompatible()) { var center1 = "1"; var center2 = "103.849"; var center = center1 + "," + center2; var Locations = "map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));map.addOverlay(new ELabel(new GLatLng(1, 103.850), 2, 'style11'));map.addOverlay(new ELabel(new GLatLng(1, 103.860), 3, 'style11'));"; var map = new GMap2(document.getElementById('map_canvas')); map.setCenter(new GLatLng(center), 5);//Note:center variable explained above,now it equal to 1,103.849 //here i want to use location variable instead.is this correct? +Locations+ map.setUIToDefault(); } }