Trying to use waypoints with JavaScript API - here-api

I'm new with MapHere, I see that with REST API side I can specify waipoints but I can't with JavaScript, I tried some parameters like 'via' but only admit one point:
var routingParameters = {
'routingMode': 'fast',
'transportMode': 'car',
// The start point of the route:
'origin': '36.8414197,-2.4628135',
'via': '37.9923795,-1.1305431',
// The end point of the route:
'destination': '40.4167047,-3.7035825',
// Include the route shape in the response
'return': 'polyline'
};
I saw an example on the main page of javascript web but I can't use waypoints:
var router = platform.getRoutingService(),
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes: 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '52.5160,13.3779', // Brandenburg Gate
waypoint1: '52.5206,13.3862' // Friedrichstraße Railway Station
};
Throwing the following error:
{"title":"Malformed request","status":400,"code":"E605001","cause":"Error while parsing request: 'origin' parameter is required\n","action":"","correlationId":"1c7bd525-b8af-4989-83a9-ab07f26a8c33"}
So, how I can send request for use waypoints?
EDIT
I saw the problem, when the .js create the url encode the second &via=
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654%26via%3D51.2234%2C9.1123&return=polyline
If I decode & and = works perfectly
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654&via=51.2234%2C9.1123&return=polyline

The JavaScript API does not yet (as of library version 3.1.18.1) support passing multiple waypoints, meaning passing an array of points to the via parameter. Your best bet around this lack of support would be to use the Routing REST API directly:
https://router.hereapi.com/v8/routes?
origin=52.550464,13.384223
&transportMode=car
&destination=52.477545,13.447395
&via=52.529791,13.401389
&via=52.513079,13.424392
&via=52.487581,13.425079
&apikey={YOUR_API_KEY}

Related

Route Via Intermediate Waypoint - Passing a list of coordinates in via parameter

I need to pass a list of coordinates within parameters in via parameter, but i don't find the way. This is an example with only one pair of coordinates(lat, lng):
function calculateRoute (platform) {
var router = platform.getRoutingService(null, 8),
routeRequestParams = {
routingMode: 'fast',
transportMode: 'truck',
origin: '36.87689,-2.44138',
destination: '36.69630,-4.47968',
via: '38.99112,-1.86902', //LIST HERE!!!
return: 'polyline'
};
router.calculateRoute(
routeRequestParams,
onSuccessRoute,
onError
);
}
The url I'm hoping to get is like this:
https://router.hereapi.com/v8/routes?apikey=
{API_KEY}&routingMode=fast&transportMode=truck&origin=36.87689,-2.44138&via=38.99112,-1.86902&via=37.95862,-1.15538&destination=36.69630,-4.47968&return=polyline
As you can see via is repeat in the URL.
Many thanks!
The JavaScript API does not (yet) support multiple routing waypoints with regards to the Routing v8 API, meaning, it does not support passing a list of coordinates to the via parameter.
So your best bet is to target the Routing v8 REST API directly, like follow, and build a polyline out of the response:
# Note: line breaks and spaces are for readability only (they need to be removed)
https://router.hereapi.com/v8/routes?
origin=52.550464,13.384223
&transportMode=car
&destination=52.477545,13.447395
&via=52.529791,13.401389
&via=52.513079,13.424392
&via=52.487581,13.425079
&apikey={YOUR_API_KEY}
Don't know if it helps you, but
function calculateRouteFromAtoB (platform) {
var router = platform.getRoutingService(),
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes : 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '55.7520,37.6175',
waypoint1: '55.8941,37.4439',
waypoint2: '55.7982,37.9680'
};
router.calculateRoute(
routeRequestParams,
onSuccess,
onError
);
}
works for me.

No results from Azure Cognitive Services Image Search API when imageType query parameter is set to "Shopping"

I am trying to use the Microsoft Cognitive Services Image Search API to search for images and return ecommerce results.
Until recently, this was working perfectly, but now any searches I perform with the query parameter imageType: 'Shopping' come back empty. If I perform the same search with any other imageType filter, or without the filter at all, I get many results, including many results where insightsSourcesSummary.shoppingSourcesCount is greater than 0.
Here is the code I wrote to call the API:
const
promise = require('bluebird');
rp = require('request-promise');
var Bing = function () {};
Bing.prototype.imageSearch = function(q, count) {
var options = {
method: 'GET',
uri: "https://api.cognitive.microsoft.com/bing/v5.0/images/search",
qs: {
q: q,
count: count,
mkt: 'en-us',
safeSearch: 'Moderate',
imageType: 'Shopping'
},
headers: {
'Ocp-Apim-Subscription-Key': '****************'
},
json: true
};
return rp(options);
}
module.exports = Bing;
Again, I did not change any code between October 2016 when it was working, and now when it is not. Is this a new bug with the API or something I'm doing wrong?
Edited: a curl example for your convenience (you will need to specify a subscription key):
curl -H "Ocp-Apim-Subscription-Key:****************" "https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=shoes&imageType=Shopping"

Filtering results from Google Analytics Reporting API

I am successfully downloading results from Google Analytics using the reporting API (version 4), with the PHP client library. But I have not figured out how to correctly filter these results.
I see how this would work via cURL, but not through the client library. I looked through the client library code, and there is a class method:
apiclient-services/Google/Service/AnalyticsReporting/ReportRequest.php:
public function setMetricFilterClauses($metricFilterClauses)
I do not see any documentation or any usage of the associated get method:
public function getMetricFilterClauses()
Are there examples of using filters through the PHP client library?
Background
The Google API Client libraries are generated from the Google Discovery Service. And the PHP client library generates a setProperty and getProperty for every property of a resource.
Analytics Reporting API V4
The Analytics Reporting API V4 reference docs exhustively describe the API. The Developer Guide gives the underlying JSON example which the client libraries will generate:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests":
[
{
"viewId": "XXXX",
"dateRanges": [
{"endDate": "2014-11-30", "startDate": "2014-11-01"}
],
"metrics": [
{"expression": "ga:pageviews"},
{"expression": "ga:sessions"}
],
"dimensions": [{"name": "ga:browser"}, {"name": "ga:country"}],
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:browser",
"operator": "EXACT",
"expressions": ["Chrome"]
}
]
}
]
}
]
}
And the Samples page gives many examples requests in Python, Java, PHP and JavaScript, which should give you a good sense of how to work with the individual client libraries. But you are correct there is not an explicit example of PHP using a filter.
PHP Filter Example
Below is the same example as the request above:
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2014-11-01");
$dateRange->setEndDate("2014-11-30");
// Create the Metrics object.
$pageviews = new Google_Service_AnalyticsReporting_Metric();
$pageviews->setExpression("ga:pageviews");
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
//Create the Dimensions object.
$browser = new Google_Service_AnalyticsReporting_Dimension();
$browser->setName("ga:browser");
$country = new Google_Service_AnalyticsReporting_Dimension();
$country->setName("ga:country");
// Create the DimensionFilter.
$dimensionFilter = new Google_Service_AnalyticsReporting_DimensionFilter();
$dimensionFilter->setDimensionName('ga:browser');
$dimensionFilter->setOperator('EXACT');
$dimensionFilter->setExpressions(array('Chrome'));
// Create the DimensionFilterClauses
$dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
$dimensionFilterClause->setFilters(array($dimensionFilter));
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId("XXXX");
$request->setDateRanges($dateRange);
$request->setDimensions(array($browser, $country));
$request->setDimensionFilterClauses(array($dimensionFilterClause));
$request->setMetrics(array($pageviews, $sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analyticsreporting->reports->batchGet( $body );
As you probably noticed I never once used a $object->getProperty(). Basically All it would do is give me its current value. When Calling the API you should only ever need to $object->setProperty($value); Hence why I gave you the background that the client libraries are generated.
Conclusion
The Analytics Reporting API itself is complex and there are many client library languages. It is not always possible to give an example every possible usage of an API in every possible client library language. That is why it is necessary to understand how to look at the reference docs and understand how the client libraries are generated from the structure described.
There is an issue with DimensionFilter() class in a script above, i get error that it is not defined, but i have changed it to Google_Service_AnalyticsReporting_DimensionFilter() class and now it is working hope that will help to someone.

trying to use params on main route (/) of my meteor app

I'm trying to use params on my main route. But in fact the params are not set and they are used in the path :
Router.map(function funcClientRouterMap(){
this.route('home', {
path: '/:_redirect?',
action: function funcClientRouterMapAction(){
console.log(this.path, this.params);
}
})
});
now if i try manual redirection here is what i get :
Router.go('home'); // it redirects on / => ok
Router.go('home', {_redirect: test}); // this.path = /test, and this.params is empty
How can i use _redirect like a params and not a route ?
Thanks
Router.go accepts a path as its first argument (per the docs). So if you were trying to programmatically cause the same result as the user going to /redirectMeSomewhere, you just use:
Router.go('/redirectMeSomewhere');
And this.params._redirect should be 'redirectMeSomewhere'.
Note that like #apendua implies, if you have other routes it could cause chaos to have a route defined as /:anything, because the other routes may never get triggered. If the above doesn't do the trick, try commenting out all your other routes to see if that changes anything.

Extjs 4 - Retrieve data in json format and load a Store. It sends OPTION request

I'm developing an app with Spring MVC and the view in extjs 4. At this point, i have to create a Grid which shows a list of users.
In my Spring MVC controller i have a Get method which returns the list of users in a jsonformat with "items" as a root.
#RequestMapping(method=RequestMethod.GET, value="/getUsers")
public #ResponseBody Users getUsersInJSON(){
Users users = new Users();
users.setItems(userService.getUsers());
return users;
}
If i try to access it with the browser i can see the jsondata correctly.
{"items":[{"username":"name1",".....
But my problem is relative to request of the Ext.data.Store
My Script is the following:
Ext.onReady(function(){
Ext.define('UsersList', {
extend: 'Ext.data.Model',
fields: [
{name:'username', type:'string'},
{name:'firstname', type:'string'}
]
});
var store = Ext.create('Ext.data.Store', {
storeId: 'users',
model: 'UsersList',
autoLoad: 'true',
proxy: {
type: 'ajax',
url : 'http://localhost:8080/MyApp/getUsers.html',
reader: {type: 'json', root: 'items'}
}
});
Ext.create('Ext.grid.Panel',{
store :store,
id : 'user',
title: 'Users',
columns : [
{header : 'Username', dataIndex : 'username'},
{header : 'Firstname', dataIndex: 'firstname'}
],
height :300,
width: 400,
renderTo:'center'
});
});
When the store tries to retrieve the data and launchs the http request, in my firebug console appears OPTIONS getUsers.html while the request in the browser launchs GET getUsers.html
As a result, Ext.data.Store has not elements and the grid appears with the columnames but without data. Maybe i've missed something
Thank you
You can change the HTTP methods that are used by the proxy for the different CRUD operations using actionMethods.
But, as you can see in the doc (and as should obviously be the case), GET is the default for read operations. So the OPTIONS request you are observing is quite puzzling. Are you sure that there's not another part of your code that overrides the default application-wide? Maybe do a search for 'OPTIONS' in all your project's JS files, to try and find a possible suspect. Apparently there's no match in the whole Ext code, so that probably doesn't come from the framework.
Edit:
Ok, I think I've got it. If your page is not accessed from the same domain (i.e. localhost:8080, the port is taken into account), the XHR object seems to resort to an OPTIONS request.
So, to fix your problem, either omit the domain name completely, using:
url: '/MyApp/getUsers.html'
Or double check that your using the same domain and port to access the page and make the requests.

Resources