Is there a way to substr a value returned by toShortString()?
I am working with openlayers and I can get a point on a map but I can't get 开发者_开发百科the individual coords.
feat = drawLayer.features[0];
var geom = feat.geometry;
var loca = geom.toShortString();
var long = loc.substr(0,9);
alert(geom.toShortString());//returns the correct coords in xx.xxx,xx.xxx format
alert(loca);//returns 2 very large numbers in xx.xxx,xx.xxx format
alert(long);//returns the first, incorrect number
What exaclty am I doing wrong and how can I correct it?
Thanks
You shouldn't use the toShortString()
method to get the individual coordinates of a geometry. It is just a convenience function to get a string describing the LonLat object (i.e "coordX, coordY").
Use the x
and y
properties instead:
var geom = feat.geometry;
var lon = geom.x; //X coordinate / Longitude
var lat = geom.y; //Y coordinte / Latitude
var parts = geom.toShortString().split(',');
var long = parts[0];
var lat = parts[1];
精彩评论