I am trying to get the travel time to a certain destination based on the time of arrival. It is available through Google Maps, But the API seems to force to enter a departure time... which I don't know. I just know the expected time of arrival.
yet...
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&traffic_model=best_guess&destinations=San+Francisco|Victoria+BC&arrival_time=1505894400&key=MY-KEY
RETURNS:
{
"destination_addresses" : [],
"error_message" : "Invalid request. Missing the 'departure_time' parameter.",
"origin_addresses" : [],
"rows" : [],
"status" : "INVALID_REQUEST"
}
Any clue? Thanks
Remove the &traffic_model=best_guess:
This works for me:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&arrival_time=1505894400&key=MY-KEY
Related
I want to fetch video analytics by date range.
I followed Video Analytics API,
https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/video-analytics-api
But I get an error.
Didn't find any other reference in the Web.
It should be noted that I fetch lifetime data (without time range parameter) successfully and that encodeURIComponent didn't help.
The request:
https://api.linkedin.com/v2/videoAnalytics?q=entity&entity=urn:li:ugcPost:6516733420171780096&type=VIEWER&aggregation=DAY&timeRange=(start:1553385600000,end:1553817600000)
The error:
{
"message": "Parameter 'timeRange' is invalid",
"status": 400
}
Edit:
using epoch - no error, but also no metrics data
even I got metrics in fetching lifetime, when fetching dateRange, and I tried several date ranges from video creation date until today - returns empty array.
{
"elements": [],
"paging": {
"total": 0,
"count": 10,
"start": 0,
"links": [],
}
}
trying fetching ALL - to mimic lifetime - also returns empty array:
https:/api.linkedin.com/v2/videoAnalytics?q=entity&entity=urn%3Ali%3AugcPost%3A6516733420171780096&type=VIEWER&timeRange=(start:1552176000,end:1564012800)&aggregation=ALL
weird - even trying to get an error by switching start date and end date returns empty array.
You need epoch time, not miliseconds
Try replacing time with
start:1563969600,end:1564401600
Converter -> https://www.epochconverter.com/
Trying (using Python) to create dynamic segment to get all sessions who completed a specific goal.
Current syntax I'm using for the metricFIlter:
"metricFilter":
{
"metricName":"ga:goal3Completions",
"operator":"NUMERIC_GREATER_THAN",
"comparisonValue":[0]
}
I've also tried other options like ['0'], 0, '0' but with no success.
Here is the response error I'm getting:
"Invalid value at 'report_requests[0].segments[0].dynamic_segment.session_segment.segment_filters[0].simple_segment.or_filters_for_segment.segment_filter_clauses[0].metric_filter.operator' (TYPE_ENUM), "NUMERIC_GREATER_THAN""
Any suggestions how to fix it ?
The operator NUMERIC_GREATER_THAN is only valid for filtering dimensions, not metrics.
"metricFilterClauses" : [
{
"filters" : [
{
"metricName" : "ga:goal3Completions",
"operator":"GREATER_THAN",
"comparisonValue": "0"
}
]
}
]
You can find a list of operators in the API docs.
I am using mapdist function from the ggmap package in R and I have a problem with results (more specifically by using the ReadLines function).
I give 2 addresses to the function, and then it connects to the Google API to return the distance between the 2 addresses.
I give an example below without calling my real addresses.
The result is empty (Status: "Not_found") with R.
$destination_addresses
[1] "Adresse numero 1, France"
$origin_addresses
[1] ""
$rows
$rows[[1]]
$rows[[1]]$elements
$rows[[1]]$elements[[1]]
$rows[[1]]$elements[[1]]$status
[1] "NOT_FOUND"
$status
[1] "OK"
Given that I was sure of my address, I copied the URL (to connect on Google API) on my browser (I tried on Mozilla, Google Chrome and Internet explorer), and I was surprised to obtain a non-empty result.
{
"destination_addresses" : [ "Adresse numero 1, France" ],
"origin_addresses" : [ "Adresse2, France" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "21,0 km",
"value" : 21045
},
"duration" : {
"text" : "17 minutes",
"value" : 1003
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
If I had only one address, the solution would be obvious. My problem is I have approximately 100 addresses with empty results and I can not check all of them.
How could you explain that the return result of ReadLines is not the same that the results on my webpage ?
Thank you for helping me.
The troubles I usually find with ggmap + R is the API does not understand the format.
I always fix this trouble checking the way google writes the address while using maps.googles.com and afterwards I make it reproductible.
I could try by my own if I could check it with real data, although you did not write it.
On the other hand you can subset all the "rows" google didn't give you the data back and try again.
I am trying to retrieve events from a Google calendar. I am calling this URL:
GET https://www.googleapis.com/calendar/v3/calendars/riteshmehandiratta%40gmail.com/events
Authorization: Bearer ya29.AHES6ZSvz3O7V2p7z_k_ZWAiUZqWX35Eyx5V_J4XC5pVSNxLjS6CNzQ
and I am getting this response:
{
"kind": "calendar#events",
"etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/_4_AQ2FVvAtAEiDFDj8_pH_usqc\"",
"summary": "riteshmehandiratta#gmail.com",
"updated": "2013-02-18T03:45:37.728Z",
"timeZone": "Asia/Calcutta",
"accessRole": "owner",
"defaultReminders": [
{
"method": "email",
"minutes": 10
},
{
"method": "popup",
"minutes": 10
}
],
"nextPageToken": "CigKGnR0ZG1xbjAyNHQ1Y3RycjYwY2x0ZGxtcTk0GAEggIDA28aNo-cT"
}
There are many events in the calendar for the past, future and for the current date.
Why its not giving the calendar event list?
there is definitely something weird here, in the response you are posting, i see you are getting the nextPageToken tag, so there actually ARE more results, you can call the next result "page", using a similar request with the variable pageToken added, something like
GET https://www.googleapis.com/calendar/v3/calendars/riteshmehandiratta%40gmail.com/events?pageToken=CigKGnR0ZG1xbjAyNHQ1Y3RycjYwY2x0ZGxtcTk0GAEggIDA28aNo-cT
that way you'll get more results.
Anyway this is weird because the nextPageToken doesn't show up if you don't limit the query with some variable like maxResults. Please check if you are not limiting the query somewhere else.
Maybe you can find useful for making test, the documentation page, that has at the bottom a request form that can build the query for you.
Hope this helps, regards
I saw the same problem. Sometimes the list API will return an empty item list with a nextPageToken, even if I did not limit the number of responses. The solution is to check if there is a nextPageToken, and make another request for the next page until you get a response without a nextPageToken.
I looped through the requests until there wasn't a nextPage token, appending the event lists to a local list, and this provided a full list of the events.
I have Postcode in my large database, which contains values like SL5 9JH, LU1 3TQ etc.
Now when I am pasting above postcode to maps.google.com it's pointing to a perfect location..
My requirement is like I want to pass post codes to maps.google.com and it should return a related latitude and longitude of that pointed location, that I want to store in my database.
So, most probably there should be some javascript for that... If anybody have another idea regarding that please provide it..
Thanks in advance...
A quick note for those finding this SO answer. The answer by Daniel Vassallo uses the Google Geocoding API V2 which has now been deprecated. The new v3 API uses a request format like this:
http://maps.googleapis.com/maps/api/geocode/output?parameters
An example for a postcode lookup, returning the data in JSON format is:
http://maps.googleapis.com/maps/api/geocode/json?address=SL59JH,+UK&sensor=false
This returns a JSON array that includes the lat and long in results->geometry->location->lat and results->geometry->location->lng
Example response:
{
"results" : [
{
"address_components" : [
{
"long_name" : "SL5 9JH",
"short_name" : "SL5 9JH",
"types" : [ "postal_code" ]
},
{
"long_name" : "Windsor and Maidenhead",
"short_name" : "Windsor and Maidenhead",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "United Kingdom",
"short_name" : "GB",
"types" : [ "country", "political" ]
},
{
"long_name" : "Ascot",
"short_name" : "Ascot",
"types" : [ "postal_town" ]
}
],
"formatted_address" : "Ascot, Windsor and Maidenhead SL5 9JH, UK",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 51.39655490000001,
"lng" : -0.66024660
},
"southwest" : {
"lat" : 51.39457330,
"lng" : -0.6624574999999999
}
},
"location" : {
"lat" : 51.39539040,
"lng" : -0.66096740
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 51.39691308029150,
"lng" : -0.6600030697084980
},
"southwest" : {
"lat" : 51.39421511970851,
"lng" : -0.6627010302915021
}
}
},
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
The API spec is available here: https://developers.google.com/maps/documentation/geocoding/
The technical term for the process you describe is called reverse geocoding. Google offers the The Google Geocoding Web Service New working Google Geocoding Link, where you can do reverse geocoding on the server side, instead of in JavaScript on the client-side.
For example, if you try the following URLs in your browser, you would get back the latitude and longitude of the postcode passed in the q parameter, in CSV format:
http://maps.google.com/maps/geo?q=SL59JH,+UK&output=csv&sensor=false
http://maps.google.com/maps/geo?q=LU13TQ,+UK&output=csv&sensor=false
This is how you would be able to reverse geocode your postcodes in php, for example:
$url = 'http://maps.google.com/maps/geo?q=SL59JH,+UK&output=csv&sensor=false';
$data = #file_get_contents($url);
$result = explode(",", $data);
echo $result[0]; // status code
echo $result[1]; // accuracy
echo $result[2]; // latitude
echo $result[3]; // longitude
Note that as Pekka suggested in another answer, the Google Maps API Terms of Use seem to prohibit the storage of the results, unless the store acts as a cache for data that will used in Google Maps. You may want to get in touch with Google and enquire on the Google Maps API Premier to have more flexible terms of use for your geocoding requirements.
The Ordnance Survey have released the postcode locations on a Creative Commons licence (CC-BY v3, IIRC). It would be a lot less hassle (and a lot clearer legally) to use that instead.
There's even a version with WGS84 (a.k.a. GPS) coordinates mirrored by mySociety
The Google Geocoding API does that, although if I remember correctly, their terms of service forbid local storage of the geocoding results.
I know this is an old question, but just chipping in here with how I managed to achieve the same thing (in PHP, but should be fairly simple):
I had a database of thousands of differently formatted postcodes. I cleaned each and every one of them up, uniformly, with this function and batch updates:
function clean_postcode($postcode)
{
$out = preg_replace("/[^a-zA-Z0-9]/", '',strtoupper($postcode));
if(strlen($out)>3)
{
$out = substr($out, 0, (strlen($out) -3)).' '.substr($out, -3);
}
return $out;
}
Now that all postcodes are formatted uniformly, I downloaded and imported the Ordnance Survey's Code-Point data set (free) - https://www.ordnancesurvey.co.uk/opendatadownload/products.html
I imported all their CSVs into my database in a separate codepoint table. From each CSV I imported the postcode, and the Eastings and Northings values.
I ran the clean_postcode() function again in batch on all the Ordnance Survey data in my DB. About 50% of the postcodes have spaces in, and 50% don't - after this they were uniformly set.
I ran the following PHP script on each and every postcode in the codepoint table and saved the Latitude and Longitude values returned into this table: http://bramp.net/blog/os-easting-northing-to-lat-long
All done! You can now match up and pull a Lat/Lon value based on well-formatted postcodes.
Further reading: http://www.deepbluesky.com/blog/-/converting-os-coodinates-into-longitude-latitude_7/
Check out ALgolia places here. Super fast, Open source and MIT