Get Latitude and Longitude [Google Api and Yahoo Api] - c#-4.0

I am working in c#.Net. My requirement is to get the latitude and longitude from the api, based on the address,city,state and zip which had given as a parameter.
I am having 350 stores details in a excel sheet. Initially i had used google api.
if (strAdd != "" && strCity != "" && strState != "" && strZip != "" && strStoreNo != "")
{
Address = strAdd.Trim() + "," + strCity.Trim() + "," + strState.Trim() + "," + strZip.Trim();
string routeReqUrl = "http://maps.google.com/maps/geo?q={0}&output=xml&oe=utf8&sensor=true_or_false&key={1}";
string url = string.Format(routeReqUrl, Address.Replace(' ', '+'), "ABQIAAAA5rV-auhZekuhPKBTkuTC3hSAmVUytQSqQDODadyYeWY4ZYaVyRRv4thyrzzOQ7AMUl_hIjoG8LomGA");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
XmlDocument xDoc = new XmlDocument();
xDoc.Load(respStream);
if (xDoc.GetElementsByTagName("coordinates")[0].InnerText.Contains(","))
{
string[] coordinates = xDoc.GetElementsByTagName("coordinates")[0].InnerText.Split(',');
string Latitude = coordinates[1];
string Longtitude = coordinates[0];
Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
}
}
In the above code, only around for 10 to 15 stores i can able to get the latitude and longitude details. After that i am getting the object reference error in "(xDoc.GetElementsByTagName("coordinates")[0].......".
After that i had tried with yahoo api, i am using the same excel sheet which had 350 stores.
dsxml.ReadXml("http://where.yahooapis.com/geocode?appid=capelinks&location=" + Address + "&Geocode=Geocode");
if (dsxml.Tables[0].Rows.Count > 0)
{
if (dsxml.Tables[1].TableName == "Result")
{
string Latitude = dsxml.Tables[1].Rows[0]["Latitude"].ToString();
string Longtitude = dsxml.Tables[1].Rows[0]["Longitude"].ToString();
Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
}
}
Here, its process all the 350 stores correctly without any error.
What will be the issue with google api. whether there are any restrictions for taking the latitude and longitude details for large number of stores.

I'm not sure if this is your example problem, but the Google Geocoding API V2 docs mention that the V2 version is deprecated now:
Note: The Google Maps Geocoding API Version 2 has been officially deprecated as of March 8, 2010. The V2 API will continue to work until Mar 8, 2013. We encourage you to migrate your code to the new Geocoding API.
You could try switching to the latest Geocoding API V3. One thing to keep in mind is Google terms mention only allowing this service when you are displaying results in the context of a Google Map.
If the Yahoo service is providing the data you need, I would stick with it.

Related

How to implement a interactive excel web addin with browser

I am implementing a excel web addin. I took a template project(excel web addin) using Visual Studio.
Here in code i need to call a URL. that will open in browser popup for login, after login it will have few events like user need to click allow access button. then it will navigate some other URL in same window. now i need to get that URL to my code.
I am able to call the URL and it is opening in browser. but after this i dont any object reference or context to control browser.
Below is the code i written.
SampleNav.js
var w = 800;
var h = 500;
var left = (screen.width / 2) - (w / 2);
var top = (screen.height / 2) - (h / 2);
var dialog = window.open("myurl", "window1", 'width=' + w + ',height=' + h + ',scrollbars=NO, top=' + top + ', left=' + left);
console.log("testDialog: " + window.location.pathname);
console.log("testDialog: " + window.location.hostname);
console.log("testDialog: " + window.location.assign);
console.log("testDialog: " + window.location.href);
console.log("testDialog: " + dialog.location.pathname);
console.log("testDialog: " + dialog.location.hostname);
console.log("testDialog: " + dialog.location.assign);
console.log("testDialog: " + dialog.location.href);
I tried to find something in dialog reference but no use
please suggest needful

How do I access table elements in cheerio?

I have a Table let's say. The elements have no classes, ids or anything except a value. They only have applied style but inside the element. The rest are TD and TR's. Now in Python and BeautifulSoup4 I can do this:
status = soup.select('._lMf')
table = soup.select('.g table td')
departure = table[8].getText()
deptime = table[4].getText() + " " + table[5].getText()
terminal = table[6].getText() + " "+ table[11].getText()
arrival = table[19].getText()
arrtime = table[15].getText() + " " + table[16].getText()
arrterminal = table[17].getText() + " " + table[22].getText()
info = table[1].getText()
Select the table and the elements i'm looking for which is a TD and access them. Now I tried almost the same techniques in Cheerio but didn't do it. I got like:
TypeError: table[5].text is not a function and Objects.
It successfully logged the easiest 2 that can be directly accessed but it fails on table elements.
This is how i do it in Cheerio:
var table = $('.g table td')
var deptime = table[5]
var city = table[8].text()
var terminal = table[6].text()
Help!
Use
var table = $('.g table td')
var deptime = table.eq(5).text()
var city = table.eq(8).text()
var terminal = table.eq(6).text()

sudden change in string value during a browse value change

During a Value-Change inside a browse, my string value suddenly changes, specifically the string(9) will change to string(0).
sample:
in my combo-box, i used a list-item-pair with following code:
cb-name:LIST-ITEM-PAIRS = ?.
cb-name:DELIMITER = '?'.
FOR EACH employee WHERE employee.date-resigned = ? NO-LOCK BY employee.employee-no.
cb-name:ADD-LAST(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + ".",employee.employee-no).
END.
cb-name:SCREEN-VALUE = cb-name:ENTRY(1).
in the value-changed of browse:
ASSIGN cb-name:SCREEN-VALUE =
STRING(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + "." ,
STRING(employee.employee-no, '99999999')).
if the employee no has a string value of 9, progress will change it to 0.. producing an error message that has an invalid value..
ex: from 819001 /*correct*/ to 810001 /*incorrect*/
if there is no string(9), it will display like:818002
if i message the STRING(employee.employee-no, '99999999')), it will display the correct string value
Version doesn't matter in this case, apparently. I just simulated it in 10.2B08 using a temp-table with the named tables. The problem is when you're assigning the screen-value to the combo you're trying to convert the whole string (employee-no + names + separators) into format 99999999.
Since your combo is list-item-pairs
('Whatever I want it to display','the real value',
'and so on display' , 'and so forth value')
your solution is to assign the screen value just to the real value, disregard the label. In other words, as simple as changing your value-changed code to
ASSIGN cb-name:SCREEN-VALUE = STRING(employee.employee-no, '99999999') .
It worked for me. Let me know if you are still having trouble with it.

xpages ftsearch documents from an interval of dates

I made an xpage element for ftsearch using a tutorial from IBM
My request: is there possible having 2 date fields ( as input requirements for the search ) to find those documents having the creation date inside the interval consisting of those 2 dates?
Should I create a computed field dtCreated where I will store the creation date and then in the search property of the view I should add something like this:
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "(Field dtCreated > \"" + sessionScope.searhcDate1 + "\")" && "(Field dtCreated < \"" + sessionScope.searhcDate2 + "\")";
}
....
....
Or there is another alternative?
My 2 session variables are having Short (5/5/14) Date format. Also, my default value for those 2 dates (session variables) are "" but of course I add some values before clicking the Submit button.
Thanks for your time!
You can use the special field _creationDate as creation date (see answer from Tommy). Based on this the following example query will work in the Notes client:
Field _creationDate > 01-01-2014 AND Field _creationDate < 01-03-2014
In order to get this query to work with your specific code do this:
var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "dd-MM-yyyy" );
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "Field _creationDate > " + dateFormatter.format(sessionScope.searchDate1) + " AND Field _creationDate < " + dateFormatter.format(sessionScope.searchDate2);
}
If you want to do an FTSearch, _CreationDate can be used
Documentation (scroll to Searching for Header Information):
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_CUSTOMIZING_SEARCH_FORMS_7304.html
E.g. (there might be typos):
tmpArray[cTerms++] = "(Field _creationDate>" + sessionScope.searhcDate1 + ") AND (Field _creationDate<" + sessionScope.searhcDate2 + ")";
Or my preferred syntax:
tmpArray[cTerms++] = "[_creationDate>" + sessionScope.searhcDate1 + "] AND [_creationDate<" + sessionScope.searhcDate2 + "]";
To build on Tommy's answer:
Specifically, try "yyyy/m/d" as the format. If those values in sessionScope are java.util.Date (the type that date fields use), you could try something like this (typing off the top of my head, not in an app, so my apologies for typos):
var tmpArray = [];
var cTerms = 0;
if(sessionScope.searchDate1 && sessionScope.searchDate2) {
var formatter = new java.text.SimpleDateFormat("yyyy/M/d");
tmpArray[cTerms++] = "[_CreationDate] >= " + formatter.format(sessionScope.searchDate1) + " and [_CreaationDate] <= " + formatter.format(sessionScope.searchDate2)
}
What you want to end up with is a FT query like:
[_CreationDate] >= 2014/1/1 and [_CreationDate] <= 2014/2/1

search view with the exact value

I have a view in which I search for products. I'm for example looking for product 1234.
The problem is their also exist products called 1234A and 1234 C etc. When I look with the code mentioned below I get all the items from product 1234 but also from 1234A and 1234 C etc.
It has to be limited to items from product 1234 only
Search code (under Data / Search in view results):
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.SelectedProduct != null & sessionScope.SelectedProduct != "") {
tmpArray[cTerms++] = "(FIELD spareProduct = \"" + sessionScope.SelectedProduct +
"\")";
}
if (sessionScope.Development != null & sessionScope.Development != "") {
tmpArray[cTerms++] = "(FIELD spareStatus = \"*" + sessionScope.Development +
"*\")";
}
qstring = tmpArray.join(" AND ").trim();
return qstring
I used the suggestion from Frantisek :
I made a view with a combined column . (combined with the different "keys" I search for)
Then instead of using data / search , I used data/keys with exact keymatch. In this key I combined the searched items.
Since I had a field in wich I had sometimes at the end a character "°" , and it seems that this character doesn't work with a lookup , I took it out of my view and searched item with #Word(FIELDNAME; "°" ; 1).
As Frantisek suggested I could have used #ReplaceSubstring( field; "°"; "" ) also.

Resources