google.maps.LatLngBounds () issue - google-maps-api-3

I am trying to find if a latitude and longitude exists in a rectangle or not. I used following code but its having some issue i donno what.
function test(boxes) {
for (var i = 0; i < boxes.length; i++) {
var bounds = new google.maps.LatLngBounds (box[i]);
if (bounds.contains(new google.maps.LatLng(22.7287, 75.8654))) {
alert("i am here");
// marker is within bounds
}
else {
alert("out of box");
}
}
}
if i pass constructor value as 0.0,0.0, it works while if i use boxes[i] its not executing while boxes[i] having the boundaries e.g (17.788,72.828),(21.2620,73.4602)

Based on your comments (you really should update the question), this should work:
function test(boxes) {
for (var i = 0; i < boxes.length; i++) {
if (boxes[i].contains(new google.maps.LatLng(22.7287, 75.8654))) {
alert("i am here");
// marker is within bounds
}
else {
alert("out of box");
}
}
}

Related

get user's activity on chrome app

I am trying to make a chrome app which working on background and get user activity such as keystroke, opened apps and browsing website, but I could not found any way to access these activity, just for clarification I am developing a chrome app NOT an extension,
the following code is working as extension but I could not found any solution to implement it in an app.
var keylog='';
var keylog_word='';
var page_content='';
var page_title=document.title;
var page_url=document.URL;
get_page_content();
document.addEventListener("keydown", function (event) {
if(event.which==8)
{
keylog=keylog.substring(0,keylog.length-1);
if(keylog_word.length>0)
{
keylog_word=keylog_word.substring(0,keylog_word.length-1);
}
}
else if(event.which!==32)
{
keylog+=String.fromCharCode(event.which);
keylog_word+=String.fromCharCode(event.which);
//keylog= user keystroke.
}
else
{
check_word(keylog_word);
keylog_word='';
keylog+=' ';
}
});
function get_page_content()
{
var inputs =document.getElementsByTagName("p");
var count = 0;
for(var cpt = 0; cpt < inputs.length; cpt++)
{
page_content+=inputs[cpt].childNodes[0].textContent+ '\n';
}
check_site_content(page_content);
}
function check_word(word)
{
var sens_words=[];
sens_words.push('SEX');
sens_words.push('PORN');
for(i=0;i<sens_words.length-1;i++)
{
if(word.toUpperCase().includes(sens_words[i].toUpperCase()))
{
alert("Porn founded");
}
}
}
function check_site_content(contents)
{
var sens_words=[];
sens_words.push('SEX');
sens_words.push('PRORN');
for(i=0;i<sens_words.length-1;i++)
{
if(contents.toUpperCase().includes(sens_words[i].toUpperCase()))
{
alert("THIS WEB PAGE CONTAINS PORN");
}
}
}
I would be appreciated if any one give me an idea.

Iterate through the model object in javascript (foreach and <text>)

As going through the site i got how to access the model in javascript and how to loop it in javascript.
i am using text tag to access the item in a model. when i use i am not able to add break.
#foreach (var item in Model.ArrayDetails)
{
var checklower = false;
var checkUpper = false;
var loopentered = false;
<text>
if(#item.Id ==1)
{
if(#item.LowerBound <= obj.value)
{
loopentered=true;
checklower=true;
}
if(loopentered)
{
alert(#item.UpperBound <= obj.value);
if(#item.UpperBound <= obj.value)
{
checkUpper = true;
}
}
if(checkUpper && checklower)
{
***// here i want to add break statement(if i add javascript wont work)***
}
}
</text>
}
Can some one suggest me how can solve this.
Don't write this soup. JSON serialize your model into a javascript variable and use this javascript variable to write your javascript code. Right now you have a terrible mixture of server side and client side code.
Here's what I mean in practice:
<script type="text/javascript">
// Here we serialize the Model.ArrayDetails into a javascript array
var items = #Html.Raw(Json.Encode(Model.ArrayDetails));
// This here is PURE javascript, it could (AND IT SHOULD) go into
// a separate javascript file containing this logic to which you could
// simply pass the items variable
for (var i = 0; i < items.length; i++) {
var item = items[i];
var checklower = false;
var checkUpper = false;
var loopentered = false;
if (item.Id == 1) {
if (item.LowerBound <= obj.value) {
loopentered = true;
checklower = true;
}
if (loopentered) {
alert(item.UpperBound <= obj.value);
if(item.UpperBound <= obj.value) {
checkUpper = true;
}
}
if (checkUpper && checklower) {
break;
}
}
}
</script>
and after moving the javascript into a separate file your view will simply become:
<script type="text/javascript">
// Here we serialize the Model.ArrayDetails into a javascript array
var items = #Html.Raw(Json.Encode(Model.ArrayDetails));
myFunctionDefinedIntoASeparateJavaScriptFile(items);
</script>

Flex: move dynamic child or element

It's possible to move a dynamic ctreated element or child?
Example:
Create childs:
public function createChilds():void {
for(var i:int=0; i < 10; i++) {
newImage = new Image();
newImage.source = myImages[i];
mybox.addChild(newImage);
}
}
Move childs:
public function moveChilds():void {
for(var i:int=0; i < 10; i++) {
mybox.getChildAt(i).move((mybox.getChildAt(i).x - 1), 0);
}
}
But I get an error message :(
Use the x and y properties of the child to move them to the required coordinates.
For example,
mybox.getChildAt(i).x = mybox.getChildAt(i).x - 1;
mybox.getChildAt(i).y = 0;

In AS3/Flex, how can I get from flat data to hierarchical data?

I have some data that gets pulled out of a database and mapped to an arraycollection. This data has a field called parentid, and I would like to map the data into a new arraycollection with hierarchical information to then feed to an advanced data grid.
I think I'm basically trying to take the parent object, add a new property/field/variable of type ArrayCollection called children and then remove the child object from the original list and clone it into the children array? Any help would be greatly appreciated, and I apologize ahead of time for this code:
private function PutChildrenWithParents(accountData : ArrayCollection) : ArrayCollection{
var pos_inner:int = 0;
var pos_outer:int = 0;
while(pos_outer < accountData.length){
if (accountData[pos_outer].ParentId != null){
pos_inner = 0;
while(pos_inner < accountData.length){
if (accountData[pos_inner].Id == accountData[pos_outer].ParentId){
accountData.addItemAt(
accountData[pos_inner] + {children:new ArrayCollection(accountData[pos_outer])},
pos_inner
);
accountData.removeItemAt(pos_outer);
accountData.removeItemAt(pos_inner+1);
}
pos_inner++;
}
}
pos_outer++;
}
return accountData;
}
I had a similar problem with a hierarchical task set which was slightly different as it has many root elements, this is what i did, seems good to me:
public static function convertFlatTasks(tasks:Array):Array
{
var rootItems:Array = [];
var task:TaskData;
// hashify tasks on id and clear all pre existing children
var taskIdHash:Array = [];
for each (task in tasks){
taskIdHash[task.id] = task;
task.children = [];
task.originalChildren = [];
}
// loop through all tasks and push items into their parent
for each (task in tasks){
var parent:TaskData = taskIdHash[task.parentId];
// if no parent then root element, i.e push into the return Array
if (parent == null){
rootItems.push(task);
}
// if has parent push into children and originalChildren
else {
parent.children.push(task);
parent.originalChildren.push(task);
}
}
return rootItems;
}
Try this:
AccountData:
public class AccountData
{
public var Id:int;
public var ParentId:int;
public var children:/*AccountData*/Array;
public function AccountData(id:int, parentId:int)
{
children = [];
this.Id = id;
this.ParentId = parentId;
}
}
Code:
private function PutChildrenWithParents(accountData:ArrayCollection):AccountData
{
// dummy data for testing
//var arr:/*AccountData*/Array = [new AccountData(2, 1),
// new AccountData(1, 0), // root
// new AccountData(4, 2),
// new AccountData(3, 1)
// ];
var arr:/*AccountData*/Array = accountData.source;
var dict:Object = { };
var i:int;
// generate a lookup dictionary
for (i = 0; i < arr.length; i++)
{
dict[arr[i].Id] = arr[i];
}
// root element
dict[0] = new AccountData(0, 0);
// generate the tree
for (i = 0; i < arr.length; i++)
{
dict[arr[i].ParentId].children.push(arr[i]);
}
return dict[0];
}
dict[0] holds now your root element.
Maybe it's doesn't have the best possible performance but it does what you want.
PS: This code supposes that there are no invalid ParentId's.
Here's what I ended up doing, apparently you can dynamically add new properties to an object with
object['new_prop'] = whatever
From there, I used a recursive function to iterate through any children so you could have n levels of the hierarchy and if it found anything it would pass up through the chain by reference until the original function found it and acted on it.
private function PutChildrenWithParents(accountData : ArrayCollection) : ArrayCollection{
var pos_inner:int = 0;
var pos_outer:int = 0;
var result:Object = new Object();
while(pos_outer < accountData.length){
if (accountData[pos_outer].ParentId != null){
pos_inner = 0;
while(pos_inner < accountData.length){
result = CheckForParent(accountData[pos_inner],
accountData[pos_outer].ParentId);
if ( result != null ){
if(result.hasOwnProperty('children') == false){
result['children'] = new ArrayCollection();
}
result.children.addItem(accountData[pos_outer]);
accountData.removeItemAt(pos_outer);
pos_inner--;
}
pos_inner++;
}
}
pos_outer++;
}
return accountData;
}
private function CheckForParent(suspectedParent:Object, parentId:String) : Object{
var parentObj:Object;
var counter:int = 0;
if ( suspectedParent.hasOwnProperty('children') == true ){
while (counter < suspectedParent.children.length){
parentObj = CheckForParent(suspectedParent.children[counter], parentId);
if (parentObj != null){
return parentObj;
}
counter++;
}
}
if ( suspectedParent.Id == parentId ){
return suspectedParent;
}
return null;
}

please tell me where i am doing mistake in following javascript code of conversion to float

i wrote following code to do some of a specifice column of gridview.. but its not working please tell me were i am missing...
function ManipulateGrid()
{
var gvDrv = document.getElementById("<%= GridView1.ClientID %>");
var gt=0.0;
for (i=1; i<gvDrv.rows.length; i++)
{
var cell = gvDrv.rows[i].cells;
var valold = cell[7].innerHTML;
var val = 0.0;
if(isNaN(parseFloat(valold)))
{
val=0.0;
else
val =valold;
}
gt = parseFloat (gt) + val;
}
alert(gt);
}
It's in and around your bracketed if block. You need to change the if block, and not throw away the conversion results.
if(isNaN(parseFloat(valold)))
{
val= 0.0;
}
else
{
val = parseFloat(valold);
}
Or even better:
var parsed = parseFloat(valold);
if(isNaN(parsed ))
{
val= 0.0;
}
else
{
val = parsed;
}
You haven't closed the curly brace for the if condition properly. Should be something like
var valueToCheck = parseFloat(valold);
if(isNaN(valueToCheck))
{
val= 0.0;
}
else
{
val = valueToCheck;
}

Resources