Here Maps API Location Address - geocoding

Here Maps: I originally used this code to get the address on a category search but now address seems to have been removed and replaced with a vicinity property in HTML. Is this correct and is there a way to gain this level of detail?
if (locations[i].address.house != undefined) {
catResults2 = catResults2 + locations[i].address.house + " "
}
if (locations[i].address.street != undefined) {
catResults2 = catResults2 + locations[i].address.street
}
if (locations[i].address.district != undefined) {
catResults2 = catResults2 + ", " + locations[i].address.district
}
if (locations[i].address.city != undefined) {
catResults2 = catResults2 + ", " + locations[i].address.city
}
if (locations[i].address.state != undefined) {
catResults2 = catResults2 + ", " + locations[i].address.state
}
if (locations[i].address.postalCode != undefined) {
catResults2 = catResults2 + " " + locations[i].address.postalCode
}
if (locations[i].address.country != undefined) {
catResults2 = catResults2 + ", " + locations[i].address.country
}
if (locations[i].address.countryCode != undefined) {
catResults2 = catResults2 + " " + locations[i].address.countryCode
};

If you are reverse geocoding the address of a location using the HERE Maps API for JavaScript (as in this example here), then a properly localized address can be obtained using
locations[i].address.text

Related

BST Path Traversal Confusion [C++]

I've created a method called pathTo which returns a string of the path taken to find a string x. Here is the method:
string BinarySearchTree::pathTo(BinaryNode* n, const string& x) const
{
if (n == NULL)
{
return "";
}
if (n->value == x)
return x;
if (x.compare(n->value) < 1)
return n->value + " " + pathTo(n->left, x);
else
return n->value +" " + pathTo(n->right, x);
return x;
}
Although the above example works, the above example does not work when I change the last if else statement by checking the right side first instead of the left likeso:
if (x.compare(n->value) > 1)
return n->value + " " + pathTo(n->right, x);
else
return n->value +" " + pathTo(n->left, x);
This provides the wrong path which is what I am confused about. Why is it that the left side needs to be checked first?

USBHIDDRIVER works in Visual Studio debug mode but not when deployed to IIS

I'm using USBHIDDRIVER to access a scale connected to our local workstation. Everything works fine when I run the WCF in Visual Studio 2012 Debug. But once I attempt to run the service in IIS it doesn't seem to recognize the USBHIDDRIVER. I have a test service in the WCF which works fine so the WCF is working.
Any information on how to troubleshoot this would be extremely helpful. My problem is that the WCF is compiled when I deploy to the IIS server so I'm having a hard time trying to troubleshoot.
Here is additional information regarding USBHIDDRIVER: http://www.florian-leitner.de/index.php/projects/usb-hid-driver-library/
namespace USBDevices
{
public class Service1 : IService1
{
public string GetWeight(string id)
{
USBHIDDRIVER.USBInterface usb = new USBHIDDRIVER.USBInterface("vid_0922","pid_8007");
//string[] list = usb.getDeviceList();
string result;
string resultDesc;
byte itemWeight;
byte itemUOM;
result = "";
resultDesc = "";
itemWeight = 0;
itemUOM = 0;
if (usb.Connect() == true)
{
usb.startRead();
Thread.Sleep(100);
for (int i = 0; i < 200; i++)
{
var weight = USBHIDDRIVER.USBInterface.usbBuffer;
var cnt = weight.Count;
itemWeight = ((byte[])weight[cnt - 1])[4];
itemUOM = ((byte[])weight[cnt - 1])[2];
}
usb.stopRead();
result = "Success";
resultDesc = "Scale Found";
Debug.WriteLine("Result: " + result + "-" + resultDesc + " - Item Weight: " + ((float)itemWeight / 10));
}
else
{
result = "Failed";
resultDesc = "Scale Not Active";
itemWeight = 0;
itemUOM = 0;
Debug.WriteLine("Result: " + result + "-" + resultDesc + " - Item Weight: " + ((float)itemWeight / 10));
}
return result + "|" + resultDesc + "|" + ((float)itemWeight / 10) + "|" + itemUOM;
}
public string XMLData(string id)
{
return "You requested product " + id;
}
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
In order to resolve the problem I had to turn on "Enable 32-Bit Applications" for the website. Believe the problem is related to the DLL's that are used but USBHIDDRIVER

Must declare the scalar variable "#UserId" in Insert statement

I am absolute beginner, I can't solve the the problem, getting error & exception is being thrown at
objCommand.ExecuteNonQuery();
Exception Message : "Must declare scalar variable #userId."
private void btnRegister_Click(object sender, EventArgs e)
{
if (tbxUserName.Text == "" || tbxPassword.Text == "")
{
MessageBox.Show("Please enter values!");
return;
}
string strConnection;
strConnection = ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString;
SqlConnection objConnection = new SqlConnection();
objConnection.ConnectionString = strConnection;
objConnection.Open();
string strSQL;
SqlCommand objCommand = new SqlCommand("SELECT * FROM LoginTable WHERE UserId='" + tbxUserName.Text + "';", objConnection);
SqlDataAdapter objAdapter = new SqlDataAdapter();
objAdapter.SelectCommand = objCommand;
objAdapter.Fill(objDataSet);
int i = objDataSet.Tables[0].Rows.Count;
if (i > 0)
{
MessageBox.Show("User Name " + tbxUserName.Text + " already exists");
tbxPassword.Text = "";
objDataSet.Clear();
}
else
{
strSQL = "INSERT INTO LoginTable(UserId, Password) VALUES(#UserId, #Password)";
objCommand.Parameters.AddWithValue("#UsesrId", tbxUserName.Text);
objCommand.Parameters.AddWithValue("#Password", tbxPassword.Text);
objCommand.CommandText = strSQL;
objCommand.ExecuteNonQuery();
objConnection.Close();
message = "Registered Successfully! " + "Welcome " + tbxUserName.Text;
this.Hide();
WelcomeForm wf = new WelcomeForm(message);
wf.Show();
}
}
You have typo in your code, change it as following.( #UsesrId != #UserId)
strSQL = "INSERT INTO LoginTable(UserId, Password) VALUES(#UserId, #Password)";
objCommand.Parameters.AddWithValue("#UserId", tbxUserName.Text);

List and count the most weight path from the root to the leafs of a binary tree

I have to return the number of nodes and the weight of the most weight path from the root to some leaf. Note that the tree is not a Binary Search Tree, is unsorted.
i.e.:
6
/ \
9 6
/ / \
3 1 19
Then, I have to return the integer 6 + 6 + 19 = 31 and print the node 6 - 6 - 19
So, this is my code:
int heavierPath ( Node * tree ) {
if ( ! tree ) return 0;
int leftWeight = heavierPath( tree->left );
int rightWeight= heavierPath( tree->right );
if ( leftWeight >= rightWeight ) {
if ( tree->left )
cout << tree->left->value << endl;
return tree->value + leftWeight;
}
else {
cout << tree->right->value << endl;
return tree->value + rightWeight;
}
};
And the result is 31, but I see all the nodes values in the terminal.
How can I do to fix it and print only the elements that lies in the heavier path? (only recursive)
Thanks!
This appears to work after I edited it.
Take a look at: http://ideone.com/OGcyun as an example.
Your problem:
Consider the graph as:
6
/ \
9 6
/ / \
3 1 19
Number each node so:
0
/ \
1 2
/ / \
3 4 5
Consider the case where you are at node 1.
You ask for the better path which gives you leftWeight = 3 and rightweight = 0 and you print the "better" path, 3. which isn't part of the end result.
The solution
To solve this problem, I passed up additional data up in a retstruct which contain the path (the heaviest path up to this point), value (to make printing easier), sum (to determine the better path).
Then I changed the function to:
retstruct* heavierPath ( Node * tree ) {
if ( ! tree ) return new retstruct();
//Get both paths
retstruct* leftWeight = heavierPath( tree->left );
retstruct* rightWeight= heavierPath( tree->right );
//Find the "heavier" path
if ( leftWeight->sum >= rightWeight->sum ) {
//Delete lighter path
delete_retstruct(rightWeight);
//Pass up the better path with the correct data
return new retstruct(leftWeight, tree->value, tree->value + leftWeight->sum);
} else {
//Delete lighter path
delete_retstruct(leftWeight);
//Pass up the better path with the correct data
return new retstruct(rightWeight, tree->value, tree->value + rightWeight->sum);
}
};
Added the delete_retstruct function:
void delete_retstruct (retstruct* path) {
if (path->path == NULL) {
delete path;
} else {
delete_retstruct(path->path);
}
}
and the printPath function:
void printPath (retstruct* path) {
if (path->path != NULL) {
std::cout << " - " << path->value;
printPath(path->path);
}
}
This is used like so:
retstruct* path = heavierPath(tree);
//Print sum
std::cout << "Sum: " << path->sum << std::endl;
//Print path
std::cout << "Path: " << path->value;
printPath(path->path);
std::cout << std::endl;
Output:
Sum: 31
Path: 6 - 6 - 19
My suggestion is to make two functions,first function will find the leaf where path from root to it is maximum. So assuming you have pointer to such leaf here is the function to print the path.
bool print(struct node *r, struct node *leaf)
{
if (r == NULL)
return false;
//will print if it is leaf or on path to leaf
if (r == leaf || print(r->left, leaf) || print(r->right, leaf) )
{
printf("%d ", r->val); // this will print in reverse order
// if you want to print from root, store values in stack and then print the value after the function call
return true;
}
return false;
}
The problem is that you are mixing printing the node with finding the sum. The later has to visit all child-nodes while printing only has to visit the ones in the path.
Below is a possible solution:
#include <iostream>
#include <unordered_map>
struct Node
{
Node(int value = 0, Node* left = nullptr, Node* right = nullptr) :
value{value},
left{left},
right{right}
{}
int value;
Node* left;
Node* right;
};
std::unordered_map<Node*, int> map;
int pathSum(Node* node)
{
if (node == nullptr)
{
return 0;
}
else if (map.find(node) == map.end())
{
return (pathSum(node->left) > pathSum(node->right))
? (map[node] = node->value + pathSum(node->left))
: (map[node] = node->value + pathSum(node->right));
}
else
{
return map[node];
}
}
void printPath(Node* node)
{
if (node == nullptr)
{
return;
}
std::cout << node->value << std::endl;
if (pathSum(node->left) > pathSum(node->right))
{
printPath(node->left);
}
else
{
printPath(node->right);
}
}
int main() {
Node* tree = new Node(6,
new Node(9,
new Node(3)),
new Node(6,
new Node(1),
new Node(19)));
std::cout << "Biggest Sum: " << pathSum(tree) << std::endl;
std::cout << "Biggest Sum Path: " << std::endl;
printPath(tree);
return 0;
}
In recursive solutions such as this, it's a good idea to cache the results hence the std::unordered_map. The code has been tested at Ideone.

PropertyData Value Array

I'm trying to get a specific value over an wmi query. I know that this value is stored in an array itself but I can't get access on it.
ManagementObjectSearcher ^searcher =
gcnew ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive WHERE PNPDeviceID LIKE '" + marshal_as<String^>(DEV_FILTER) +"%'");
for each (ManagementObject ^drive in searcher->Get())
{
for each (ManagementObject ^o in drive->GetRelated("Win32_DiskPartition"))
{
for each (ManagementObject ^logDisk in o->GetRelated("Win32_LogicalDisk"))
{
Console::WriteLine(
"Disk: " + drive["Caption"]
+ "\n\tSize : " + drive["Size"]
+ "\n\tDriveLetter : " + logDisk["Name"]
+ "\n\t" + drive["PNPDeviceID"]
+ "\n\tSerialNumber: " + drive["SerialNumber"]
+ "\n\t" + drive["Capabilities"]
+ "\n\tRevision : " + drive["FirmwareRevision"]);
}
}
}
on Debug investigation, I can see every single Value of drive["Capabilites"] but everything I've tried so far, I can't get this array's child values.
I want to do this in c++,
every help is appreciated.
To access such values you must cast the property and an array and then iterate over the elements. try this C++ CLI sample code.
#include "stdafx.h"
#using <system.management.dll>
using namespace System;
using namespace System::Management;
int main(array<System::String ^> ^args)
{
ManagementObjectSearcher ^searcher =
gcnew ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive");
for each (ManagementObject ^drive in searcher->Get())
{
for each (ManagementObject ^o in drive->GetRelated("Win32_DiskPartition"))
{
for each (ManagementObject ^logDisk in o->GetRelated("Win32_LogicalDisk"))
{
Console::WriteLine(
"Disk: " + drive["Caption"]
+ "\n\tSize : " + drive["Size"]
+ "\n\tDriveLetter : " + logDisk["Name"]
+ "\n\t" + drive["PNPDeviceID"]
+ "\n\tSerialNumber: " + drive["SerialNumber"]
+ "\n\tRevision : " + drive["FirmwareRevision"]);
Console::WriteLine("Capabilities");
for each(UInt16 v in (array<UInt16>^)(drive->Properties["Capabilities"]->Value))
{
Console::WriteLine(v);
}
}
}
}
Console::ReadLine();
return 0;
}