I am trying to retrieve multiple values from a for loop to be pass into the esri.Geocoding function, but the problem is it only returned the first value and repeat it according to the number of records instead of returning the next value and so on. Any help is appreciated, thank you.
for (var i = 0; i < planes.length; i++) {
var lat2 = planes[i][1];
var lon2 = planes[i][2];
var time2 = planes[i][0];
L.esri.Geocoding.reverseGeocode()
.latlng([lat2, lon2])
.run(function(error, result) {
if (error) {
return console.log("empty");
} else {
//markers.bindPopup("Time: " + time2 + "<br/>Location: " + result.address.Match_addr);
//markers.addTo(mymap);
alert(lat2 + ", " + lon);
}
});
}
Used 'let' instead of 'var' seems fix the problem.
Related
I am trying to animate a line based on the given coordinates array comprising of latitude and longitude and I want to call my function just once and my coordinates name is: replayData.
map.on('postcompose', function (event) {
var vectorContext = event.vectorContext;
var frameState = event.frameState;
vectorContext.setFillStrokeStyle(null, animatedLineStroke);
var features = lineVectorSource.getFeatures();
for (var k = 0; k < features.length; k++) {
var feature = features[k];
if (!feature.get('finished')) {
var coords = feature.getGeometry().getCoordinates();
var elapsedTime = frameState.time - feature.get('start');
var elapsedPoints = elapsedTime * pointsPerMs;
if (elapsedPoints >= coords.length) {
feature.set('finished', true);
}
var maxIndex = Math.min(elapsedPoints, coords.length);
var currentLine = new ol.geom.LineString(coords.slice(0, maxIndex));
if (feature.get('iValue') == undefined || feature.get('iValue') < k) {
// drawMovingCarMarker(coords, k);
feature.set('iValue', k)
}
vectorContext.drawLineStringGeometry(currentLine, feature);
}
}
frameState.animate = true;
});
What this function is doing is first collecting all the values from for loop and then starting the animation. And because of this if I've 5 points the line between first two points will be drawn 5 times then 4,3, and so on.
Any help would be entertained. Thanks in advance.
I have this code and I want commas in my numbers.
The jackpot is €169.85 but it is displayed as 16985 00 in the game. How to fix that?
public function jackpotstring():String {
var myPattern:RegExp = /./;
var jp:Number = jackpot * denom;
var s:String = jp.toFixed(2)+"";
return s.replace(/[^A-Za-z0-9 \-_:]+/g, ' ');
}
ou could try something like;
var jp:Number = jackpot * denom;
jp = Math.round(jp * 100)/100; // value should be something like 1698500
jp = jp / 10000; // value should be something like 169.85 now
var s:String = String(jp);
return s;
I am facing a problem in the following script. I am not much into scripting at all and this is not my script also but here am getting the result which is grouping the values( For Example if i have a value A in three cells it should return the value as 3 instead it is returning AAA. Can someone help me out to count the values and return it
Thanks in Advance,
Here is the script :
function sumBackgroundColors(rangeString, color) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var sumRange = s.getRange(rangeString);
//var sum = 0;
var openCount = 0;
var sumRangeBackground = sumRange.getBackgroundColors();
var sumRangeValues = sumRange.getValues();
for(var row = 0; row < sumRangeBackground.length; row++ ) {
for(var col = 0; col < sumRangeBackground[0].length; col++ ) {
if( sumRangeValues[row][col]=="LG M"&& sumRangeBackground[row][col] == color ) {
openCount = openCount + sumRangeValues[row][col];
//if(sumRangeBackground[row][col] == color && sumRangeValues[row][col] == 1 ) {
// sum = sum + parseFloat(sumRangeValues[row][col]);
}
}
}
return openCount;
//return sum;
}
Here is a function which will take the value to be searched as argument. Rest of the things have been explained in comment lines.
function searchCount(value){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//Get the whole data from activesheet in a 2D array
var data = sheet.getDataRange().getValues();
//Initialize counter
var count = 0;
//Iterate through the array
for(var i in data){
for(var j in data[i]){
// if a match found, increament the counter
if(value.toString == data[i][j]){
count++;
}
}
}
// return the count value
return count;
}
your problem could be due to openCount = openCount + sumRangeValues[row][col];
According to your example sumRangeValues[row][col] isn't an int. int + not an int = ??? if you want to keep a count of things you probably want openCount++ to replace that line instead, which is just a shortcut to openCount = openCount + 1;
Even if sumRangeValues[row][col] was an int, that line still wouldn't be what you're looking for. If you're searching for all the 3s in your spreadsheet your code would find your first 3, and then that line would execute 0 = 0 + 3 congrats, you just found 3 threes. You would continue to add three every time you found a three.
Waqar's code is essentially your code (amazingly simplified, but it iterates the same way) except he doesn't check color and he uses ++ instead of that line.
I need to format numbers with commas as thousand seperators, for example:
1234 = 1,234
1234.50 = 1,234.50
12345.60 = 12,345.60
123456.70 = 123,456.70
1234567.80 = 1,234,567.80
etc etc
This needs to work for numbers with decimal values or without
i.e. both 1234567.80 and 1234567
This is for Actionscript 2 in a Coldfusion / Flash application, so normal actionscript is being used. I have seen a couple of solutions on the net but none quite do the trick.
So far I have the function below, but it is not formatting correctly when decimals are provided.For example: 21898.5 becomes 2,188,8.5.
Please could you help me find the bug or offer an alternative solution that fulfils the requriements.
Thanks
_global.NumberFormat = function(theNumber)
{
var myArray:Array;
var numberPart:String;
var decPart:String;
var result:String = '';
var numString:String = theNumber.toString();
if(theNumber.indexOf('.') > 0)
{
myArray = theNumber.split('.');
numberPart = myArray[0];
decPart = myArray[1];
}
else
{
numberPart = numString;
}
while (numString.length > 3)
{
var chunk:String = numString.substr(-3);
numString = numString.substr(0, numString.length - 3);
result = ',' + chunk + result;
}
if (numString.length > 0)
{
result = numString + result;
}
if(theNumber.indexOf('.') > 0)
{
result = result + '.' + decPart;
}
//alert('Result: ' + result);
return result;
}
You could try this:
_global.NumberFormat = function(numString)
{
numString = String(numString);
var index:Number = numString.indexOf('.');
var decimal:String;
if(index > 0) {
var splitByDecimal:Array = numString.split(".");
//return NumberFormat(splitByDecimal[0])+"."+splitByDecimal[1];
numString = splitByDecimal[0];
decimal = splitByDecimal[1];
} else if(index === 0) {
return "0"+numString;
}
var result:String = '';
while (numString.length > 3 ) {
var chunk:String = numString.substr(-3);
numString = numString.substr(0, numString.length - 3);
result = ',' + chunk + result;
}
result = numString + result;
if(decimal) result = result + "." + decimal;
return result;
}
It splits the number by the decimal if present(compensating for an illegal '.01234' if required), and uses recursion so call itself on the split element.
For your example numbers this traces:
1,234
1,234.50
12,345.60
123,456.70
1,234,567.80
Just for fun
This is why your original code didn't work:
After creating a string representation of the number (var numString:String = theNumber.toString();) you then carried on using the actual number rather than the string version.
After assigning a value to number part you then continued to perform operations on numString rather than numberPart.
A corrected version looks like this:
_global.NumberFormat = function(theNumber)
{
var myArray:Array;
var numberPart:String;
var decPart:String;
var result:String = '';
var numString:String = theNumber.toString();
if(numString.indexOf('.') > 0)
{
myArray = numString.split('.');
numberPart = myArray[0];
decPart = myArray[1];
}
else
{
numberPart = numString;
}
while (numberPart.length > 3)
{
var chunk:String = numberPart.substr(-3);
numberPart = numberPart.substr(0, numberPart.length - 3);
result = ',' + chunk + result;
}
if (numberPart.length > 0)
{
result = numberPart + result;
}
if(numString.indexOf('.') > 0)
{
result = result + '.' + decPart;
}
//alert('Result: ' + result);
return result;
}
public static function formatNumberString(value:Number,separator:String):String {
var result:String = "";
var digitsCount:Number = value.toString().length;
separator = separator || ",";
for (var i:Number = 0; i < digitsCount; i++) {
if ((digitsCount - i) % 3 == 0 && i != 0) {
result += separator;
}
result += value.toString().charAt(i);
}
return result;
}
Try this out, works fine for me:
var largeNumber:String=new String(1000000.999777);
var fAr:Array=largeNumber.split(".");
var reg:RegExp=/\d{1,3}(?=(\d{3})+(?!\d))/;
while(reg.test(fAr[0]))
fAr[0]=fAr[0].replace(reg,"$&,");
var res:String=fAr.join(".");
trace(res);
Trace: 1,000,000.999777
i used a CurrencyFormatter to parse 2 number into its currency representation
currencyFormat.format("10" + "." + "99") ---> $10.99
I'm curious if there is a way to parse a string "$10.99" back to a number / double ?
so it is possible to get the value on the left side of the decimal and right side of the decimal.
thanks,
You could do this a number of ways. Here are 2 off the top of my head:
function currencyToNumbers($currency:String):Object {
var currencyRE:RegExp = /\$([1-9][0-9]+)\.?([0-9]{2})?/;
var val = currencyRE.exec($currency);
return {dollars:val[1], cents:val[2]};
}
function currencyToNumbers2($currency:String):Object {
var dollarSignIndex:int = $currency.indexOf('$');
if (dollarSignIndex != -1) {
$currency = $currency.substr(dollarSignIndex + 1);
}
var currencyParts = parseFloat($currency).toString().split(".");
return {dollars:currencyParts[0], cents:currencyParts[1]};
}
var currency:Object = currencyToNumbers('$199.99');
trace(currency.dollars);
trace(currency.cents);
var currency2:Object = currencyToNumbers2('$199.99');
trace(currency2.dollars);
trace(currency2.cents);