Google maps - Status Codes - GeocoderStatus - google-maps-api-3

Im having troubles with the geocoderStatus, basically I always got "google.maps.GeocoderStatus.OK"
when I send a request even if the address is invalid or zero results,
This is my code
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var lon = results[0].geometry.location.lng();
searchStores(lat, lon);
} else {
$addressErrorP.removeClass('hide');
}
For example:
If I send this address "1525 COLD SPRINGS RD, CA" I get this:
latitude=38.746431&longitude=-120.86995890000003, which is ok
And if I send this as an address "#$^%#$^%#%#%#%#$%" I get this:
33.778175&longitude=76.57617140000002 which is nowhere
https://www.google.co.cr/maps/place/33%C2%B046'41.4%22N+76%C2%B034'34.2%22W/#33.778175,-76.5761714,17z/data=!3m1!4b1!4m2!3m1!1s0x0:0x0?hl=en
So what I need to know when there is zero results to show an error message and not reload the page with the nowhere location , but I never get other thing that status OK
This is the documentation in https://developers.google.com/maps/documentation/javascript/geocoding:
Status Codes
The status code may return one of the following values:
google.maps.GeocoderStatus.OK indicates that the geocode was successful.
google.maps.GeocoderStatus.ZERO_RESULTS indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latng in a remote location.
google.maps.GeocoderStatus.OVER_QUERY_LIMIT indicates that you are over your quota. Refer to the Usage limits exceeded article in the Google Maps API for Work documentation, which also applies to non-Business users, for more information.
google.maps.GeocoderStatus.REQUEST_DENIED indicates that your request was denied for some reason.
google.maps.GeocoderStatus.INVALID_REQUEST generally indicates that the query (address or latLng) is missing.

Related

equalTo() is failing to return expected response

Needed Details
I am using Dialogflow fulfillment for my project along with Firebase realtime database. My database has a structure:
Let me first tell you about the structure of the database. It has got a list of ATMs(automated teller machine) with its full address and other needful information. I need to fetch all the ATMs with a given value of Pin number, and the given value of Pin number will come from an API response. This Pin number is nothing but the Zip Code for that ATM. So obviously, with a Pin number, there can be many ATMs.
My problem
Below is the code I am using to make an API call and Firebase database querying with received Pin value as the response from API.
var ref = db.ref("atms/");
var response = await axios.get('some URL'); //API call
var zipcodes = response.data.search_results; // Array of Pin values
console.log(zipcodes[2].postal_code); //This prints a Pin value 721304, which confirms successful response from API
ref.orderByChild("Pin").equalTo(zipcodes[2].postal_code).on("child_added", function(snapshot) { //this line is the problem
console.log(snapshot.val());
});
But the above code with equalTo(zipcodes[2].postal_code) does not give any response. But when I replace it with equalTo(721304), it does give an expected response. To emphasize, both equalTo(zipcodes[2].postal_code) and equalTo(721304) are necessarily same.
I need to use this equalTo(zipcodes[2].postal_code) only because I will be running a loop over this query, which is because of the need to query many, many Pin at once.
Could you please help me understand what is wrong here and how do I implement what I am trying to do here? Please let me know in case of any follow-up questions.
As shown by console.log(typeof zipcodes[2].postal_code); (see comments above), the value of zipcodes[2].postal_code is not of type number but of type string. You need to convert it to number, as follows:
ref.orderByChild("Pin").equalTo(Number(zipcodes[2].postal_code)).on("child_added", function(snapshot) { //this line is the problem
console.log(snapshot.val());
});

HERE LinkId from route not found in PDE (Platform Data Extension)

UPDATE: It's happening again, also with Fleet API. Please see additional examples at end of the post.
I'm using HERE's REST API to calculate a route, then ask for additional data for each link / route segment by querying HERE's Platform Data Extension (PDE). This usually works fine, but now I've run into a link id that is not recognised by PDE.
Are these services not in sync, or am I doing something wrong?
I didn't have any issue in the past weeks, and it still works fine for most link ids, so this could either be a new problem or a very singular issue. I searched in the HERE API documentation and on Stackoverflow, but couldn't find anything related.
Route request (A24 Berlin towards Hamburg): https://route.api.here.com/routing/7.2/calculateroute.json?waypoint0=geo!52.7091,13.0356&waypoint1=geo!52.7193,12.9608&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
The json response (below) contains a link with permanent id 1199057935 at Anschlussstelle Kremmen.
The PDE request gives an empty response: https://pde.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1199057935&app_id=xxx&app_code=yyy
{"Layers":[]}
Instead, I would expect the data of the containing tile, e.g. what I get for 1199057936
{"Layers":[{"layer":"ROAD_GEOM_FC1","level":9,"tileXYs":[{"x":548,"y":405}]}]}
I also tried the PDE request with ROAD_GEOM_FC1 and prefixing the id with + (values=+1199057935). Other link ids of the route return the expected tile information.
For completeness, here's the link's json from the routing response:
{
"linkId":"+1199057935",
"shape":["52.7175629,12.976613","52.7177131,12.9749393"],
"firstPoint":28,
"lastPoint":29,
"length":114,
"remainDistance":1095,
"remainTime":39,
"nextLink":"+1199057936",
"maneuver":"M2",
"speedLimit":33.3333359,
"dynamicSpeedInfo":{"trafficSpeed":16.3888893,"trafficTime":7,"baseSpeed":27.5,"baseTime":4,"jamFactor":5.7118645},
"flags":["motorway"],
"functionalClass":1,
"roadNumber":"A24",
"timezone":"+0100",
"roadName":"",
"consumption":0,
"_type":"PrivateTransportLinkType"
}
UPDATE 2019-05-27:
I get a route that contains link id 1239826684 from https://route.api.here.com/routing/7.2/calculateroute.json?waypoint0=geo!52.5066,13.4299&waypoint1=geo!52.5282,13.4265&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
Using fleet endpoint redirects to same call as above, including link id 1239826684: https://fleet.api.here.com/2/calculateroute.json?waypoint0=geo!52.5066,13.4299&waypoint1=geo!52.5282,13.4265&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
PDE returns [] for that link id: https://pde.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1239826684&app_id=xxx&app_code=yyy
Fleet API returns [] for that link id: http://fleet.cit.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1239826684&app_id=xxx&app_code=yyy
Seems the underlying geo-data is not in sync, and using different APIs does not help. Any other solution?
You can try Fleet telematics group of API's over basic routing and PDE as Fleet Telematics provides whole routing solution .
Please find the below API request which is giving expected response for the id-1199057935
http://fleet.cit.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1199057935&app_id=xxxx&app_code=yyyy
Response :
{
Layers: [
{
layer: "ROAD_GEOM_FC1",
level: 9,
tileXYs: [
{
x: 548,
y: 405
}
]
}
]
}
for more information kindly go through the below documentation
https://developer.here.com/documentation/fleet-telematics/api-reference.html#operation%2FindexJSONUsingGET
Hope this will help.

Search for campaign groups using LinkedIn Ads API always return 400 Bad Request

Using LinkedIn Ads API document on this page -> https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads/account-structure/create-and-manage-campaign-groups#search-for-campaign-groups
If I search for campaign groups with completed status, it will always return 400 Bad Request with following message
{
"message": "{field=ID, order=ASCENDING} does not provide a valid value for sort.field for CampaignGroupSort. The acceptable values for field: ID,ACCOUNT,NAME",
"status": 400
}
As you can see from the message itself, I've already used ID as sort's field. Following is a request url that causing error
https://api.linkedin.com/v2/adCampaignGroupsV2?q=search&sort.field=ID&sort.order=ASCENDING&search.status.values[0]=COMPLETED
However, this issue doesn't happened if I just changed search.status.values from COMPLETED to something else e.g. ACTIVE. Like the following request
https://api.linkedin.com/v2/adCampaignGroupsV2?q=search&sort.field=ID&sort.order=ASCENDING&search.status.values[0]=ACTIVE
Above request returns with http status 200 with success result.
I've tried many combinations with no luck. Anyone can help please?
https://api.linkedin.com/v2/adCampaignGroupsV2?q=search&sort.field=ID&sort.order=ASCENDING&search.status.values[0]=COMPLETD
There is a typo in COMPLETED for your search.status.values[0].

ActionMailer.net/ActionMailerNext - how to confirm if an eMail has even been sent?

Working with ActionMailerNext, which is a fork of the now-dead ActionMailer.net, and I cannot for the life of me figure out how to determine if the eMail has been sent, or if an error occurred that prevented the eMail from being sent.
Neither site provides any idea on how to do this. Two hours of Googling has been similarly productive (NOT!).
Typically, with something like a database update, I can do a
if((await _db.SaveChangesAsync()) > 0){ ... }
and be able to fork the code between yes-it-updated and no-it-failed portions. I need to be able to do this with ActionMailerNext, and I haven’t a clue how.
The actual .Deliver() returns a
System.Collections.Generic.IList<ActionMailerNext.Interfaces.IMailResponse>
But I have no clue how to unpack it because I have no idea what is inside it. Any attempt to google IMailResponse does not bring me back anything of use.
EDIT:
For those who would like to know, the returned collection contains two variables: a string Email and an Enum called DeliveryStatus that provides one of four responses for each eMail sent: DELIVERED, INVALID, QUEUED and REJECTED. By doing the following, even if only one eMail was sent (because my needs are simple):
if(e.All(x => x.DeliveryStatus == DeliveryStatus.DELIVERED)) {
// Do if ALL eMails were sent
} else {
// Fallback if ANY eMail was not sent
}
I was able to ensure that a fallback existed if one or more eMails failed to get sent.
Keep in mind, though: this only is for eMails getting delivered to the outgoing SMTP server; the system has no clue what happens beyond that.
Thanks to #ADyson below for the poke needed for my sleep-deprived brain to function correctly.
For those who would like to know, the returned collection contains two variables: a string Email and an Enum called DeliveryStatus that provides one of four responses for each eMail sent: DELIVERED, INVALID, QUEUED and REJECTED. By doing the following, even if only one eMail was sent (because my needs are simple):
if(e.All(x => x.DeliveryStatus == DeliveryStatus.DELIVERED)) {
// Do if ALL eMails were sent
} else {
// Fallback if ANY eMail was not sent
}
I was able to ensure that a fallback existed if one or more eMails failed to get sent.
Keep in mind, though: this only is for eMails getting delivered to the outgoing SMTP server; the system has no clue what happens beyond that.
Thanks to #ADyson for the poke needed for my sleep-deprived brain to function correctly.

Response 202 from Emotion API in R but Operation Location Says Invalid Key

I am trying to reproduce in R the Microsoft Emotion API program located here. I obtained my API key from Microsoft's website and plugged it into the following code (also from the above linked page:
library(httr)
apiUrl <- 'https://api.projectoxford.ai/emotion/v1.0/recognizeInVideo?outputStyle=perFrame'
key <- '2a0a91c98b57415a....'
urlVideo <- 'https://drive.google.com/file/d/0B5EuiMJDiDhWdWZSUGxvV3lJM0U/view?usp=sharing'
mybody <- list(url = urlVideo)
faceEMO <- httr::POST(
url = apiUrl,
httr::content_type('application/json'),
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)),
body = mybody,
encode = 'json'
)
operationLocation <- httr::headers(faceEMO)[["operation-location"]]
The request appears to go through successfully as the "faceEMO" object returns a Response 202 code which according to Microsoft's website means:
The service has accepted the request and will start the process later.
In the response, there is a "Operation-Location" header. Client side
should further query the operation status from the URL specified in
this header.
However, when I open the given URL from the 'operationLocation' object, it says:
{ "error": { "code": "Unauthorized", "message": "Access denied due to
invalid subscription key. Make sure you are subscribed to an API you
are trying to call and provide the right key." } }
This seems to indicate that my request didn't go through after all.
Not sure why it would say my key is invalid. I tried to regenerate the key and run it again but received the same result. Maybe it has something to do with the fact that Microsoft gives me 2 keys? Do I need to use both?
To add additional info, I also tried running the next few lines of code given from the linked web site:
while(TRUE){
ret <- httr::GET(operationLocation,
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)))
con <- httr::content(ret)
if(is.null(con$status)){
warning("Connection Error, retry after 1 minute")
Sys.sleep(60)
} else if (con$status == "Running" | con$status == "Uploading"){
cat(paste0("status ", con$status, "\n"))
cat(paste0("progress ", con$progress, "\n"))
Sys.sleep(60)
} else {
cat(paste0("status ", con$status, "\n"))
break()
}
}
When I run this I'm shown a message indicating "status Running" and "progress 0" for about 30 seconds. Then it shows "status Failed" and stops running without giving any indication of what caused the failure.
It seems the API requires a direct download link, instead of what you supplied. Normally, you could simply change the url to...
urlVideo <- "https://drive.google.com/uc?export=download&id=0B5EuiMJDiDhWdWZSUGxvV3lJM0U"
I've confirmed that the Emotion API works on small test videos I've uploaded to Google Drive. Unfortunately, the issue now is that your specific video file is large enough that you run into the annoying Google Drive can't scan this file for viruses interruption. As far as I can tell, no workaround exists to bypass this. More on this here.
Your best bet is to host the video somewhere other than Google Drive, and make sure the body for the post call contains the direct download link.

Resources