Map API

MGMaps Lib SDK is professional toolkit to develop mobile mapping applications.
Platforms: iPhone, Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »
Untitled Document

Products

Latest news

Last at Mon, 6 Sep 2010 12:27:06
Topic: Let your feedback ideas flow
See more news »

Nutiteq on Twitter

11 weeks 6 days ago Nutiteq is proud sponsor of StateOfTheMap 2010 #sotm10

Example how to use CloudMadeDirections

18 replies [Last post]
marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

Hello,

Is there a good example how to use CloudMadeDirections?

If I look in the documentation(Javadoc) is didn't get the point how to use it.

this is what I have now. But this doesn't doe anything:"

NutiteqRouteWaiter dW = new NutiteqRouteWaiter();
WgsPoint fPoint = new WgsPoint(source.getLongitudeE6(), source.getLatitudeE6());
WgsPoint tPoint = new WgsPoint(source.getLongitudeE6(), source.getLatitudeE6());
CloudMadeDirections client = new CloudMadeDirections(dW, fPoint, tPoint, CloudMadeDirections.ROUTE_TYPE_FOOT, "222c0ceb31794934a888ed9403b005d8");
client.execute();

can someone give me a good example or better documentation?

thanks in advance

jaak
User is online Online
Joined: 06/19/2008

Have you checked the "directions" sample of J2ME? This should give the basics.

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

Yes i looked here. I try to implement this. but i can't find out when the new thread is calling the function DirectionsWaiter.routeFound() when executed the cloudMadeDirections.execute() function

jaak
User is online Online
Joined: 06/19/2008

This is called when response has been received and successfully parsed from the server.

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

ok so when i called:

new CloudMadeDirections(instance,startCoordinates, endCoordinates, "Foot", "222c0ceb317????a888ed9403a005d8").execute()

automatically the function routeFound() is called or one of the error functions from the instance is called by an error?

can this be done without a new thread, because i can't get working. Maybe i make a little mistake but i tried it now for a long time

thanks in advance

jaak
User is online Online
Joined: 06/19/2008

It should work also without new thread. I suggest to check network (HTTP) traffic: maybe server responds something strange, or nothing at all? Also log would help to check it.

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

I tried it in a new application and now i get the networkError.

with log i trace:

http://routes.cloudmade.com/222c0ceb31794????888ed9403a005d8/api/0.3/4.890935,52.373801,5.912361,51.979805/Foot.gpx

and if i fill this in my browser i get:

Forbidden, no token in query

how can i solve this problem?

jaak
User is online Online
Joined: 06/19/2008

CloudMade requires tokens in routing queries since May, 1st. You should use latest beta library from www.nutiteq.com/beta/lib . Note that CloudMadeDirections constructor has additional String type parameter End-user ID, which is now needed for CloudMade API (to generate the token).

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

i tried it with the new lib. but still no succes...

now this:

CloudMadeDirections cMD = new CloudMadeDirections(nutiteqRouteWaiter,nutiteqRouteWaiter.getStartCoordinates(), nutiteqRouteWaiter.getEndCoordinates(), "Foot",CloudMadeDirections.ROUTE_TYPE_MODIFIER_SHORTEST ,"222c0ceb31794934a777ed9403a005d8");

then getting the error:


java.io.FileNotFoundException: http://auth.cloudmade.com/token/shortest?userid=222c0ceb31794934a777ed94...
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
at com.nutiteq.android.http.AndroidHttpConnection.openInputStream(Unknown Source)
at com.nutiteq.android.http.AndroidHttpConnection.openDataInputStream(Unknown Source)
at com.nutiteq.services.CloudMadeDirections.getCloudMadeToken(Unknown Source)
at com.nutiteq.services.CloudMadeDirections.(Unknown Source)
at com.nutiteq.services.CloudMadeDirections.(Unknown Source)
at com.tutorial.DummyStarter.run(DummyStarter.java:17)
at java.lang.Thread.run(Thread.java:1060)

and later from de debugger:


Error > Downloader: http://routes.cloudmade.com/shortest/api/0.3/4.890935,52.373801,5.912361,51.979805/Foot.gpx?token=null

jaak
User is online Online
Joined: 06/19/2008

From where have you got the org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection ? For J2ME it should be javax.microedition.io.HttpConnection, for example. What is your platform?

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

mm I'm using the android platform. so also the android lib.

jaak
User is online Online
Joined: 06/19/2008

Same imports should work there also. Nutiteq Android Lib has a wrapper for needed J2ME classes, including HTTP Connection, so you can reuse them in your app too:

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

I don't understand what you mean. where do I need to import this I never used it. what I do is this:

in HelloMap.java:


WgsPoint fPoint = new WgsPoint(52.373801, 4.890935);
WgsPoint tPoint = new WgsPoint(51.979805, 5.912361);
new NutiteqRouteWaiter(fPoint, tPoint);

in NutiteqRouteWaiter.java:


public NutiteqRouteWaiter(WgsPoint startCoordinates, WgsPoint endCoordinates) {
instance = this;
this.startCoordinates = startCoordinates;
this.endCoordinates = endCoordinates;

starter = new Thread(new DummyStarter(instance));
starter.start();
}

and in DummyStarter.java

public void run() {
CloudMadeDirections cMD = new CloudMadeDirections(nutiteqRouteWaiter,nutiteqRouteWaiter.getStartCoordinates(), nutiteqRouteWaiter.getEndCoordinates(), "Foot",CloudMadeDirections.ROUTE_TYPE_MODIFIER_SHORTEST ,"222c0ceb31794934a888ed9403a005d8");
cMD.execute();
}

Can you please tell me what I do wrong?

I'still getting the error from above

thansk in advance

jaak
User is online Online
Joined: 06/19/2008

It is strange from where the org.apache.harmony... import comes. Can you send your Android project as zip file to support@nutiteq.com, so we can take a look to it?

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

I send you the email with the project as attachment.

jaak
User is online Online
Joined: 06/19/2008

1) All CloudMade services should now have extra parameter userId. So both map and Directions services have additional parameter. This is used to generate proper tokens in CloudMade. Note: this is END-USER identificator, not developer ID, so you should not put some static text there. Technically, it has to be a textual/numeric value. For example it could be:

a) hash of your application end-user email would be nice,

b) you can request IMSI from Android Telephony API,

c) Generate (and memorize in app persistent
storage) random number for each end-user.

The specific error message comes as you do not have userId parameter added and constructor parameter values are misinterpreted. Just add userId as last parameter value as String. I made incorrect quick fix as:

CloudMadeDirections cMD = new CloudMadeDirections(
 nutiteqRouteWaiter,
 nutiteqRouteWaiter.getStartCoordinates(),
 nutiteqRouteWaiter.getEndCoordinates(),
 "Car",
 CloudMadeDirections.ROUTE_TYPE_MODIFIER_SHORTEST ,
 "222c0ceb31794934a888ed9403a005d8",
 "myUser123");

2) Suggestion: add following lines to onCreate, so you see library logs. You had the first one missing.

Log.setLogger(new AndroidLogger("HelloMap"));
Log.enableAll();

3) For some reason CloudMade server gives "Sorry, some unrecoverable error happened" for particular request. When I changed "Foot" to "Car", then it gave route. Perhaps the route was just too long for walking.

4) If your routeFound() method gives some exception, then you get "shadow error" also in your error listener. It could be confusing, as it seems that something is wrong with directions service (and especially as the method name is networkError), but actually the error was in the application. At least I just got fooled with this. In your case, you had bad line:

Log.info(route.getRouteSummary().getDistance().toString());

If routeSummary is null here, then you'll have NullPointerException here. CloudMade did not provide route summary with GPX, this method can be used with some other service APIs (e.g. OpenLS). Actually now it provides some summary, I'll take a look if I can parse and add it easily.

5) To show line on map I made mapComponent object in your HelloMap public and static, and added just one line to your routeFound method:

	   HelloMap.mapComponent.addLine(route.getRouteLine());

And it seems to work fine now.

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

Wit finally works. thanks a lot for the great support. :) only the little END-USER was the problem.

I send CloudMade an email about the foot/car problem, because even with small routes it gives an error. I will post their answer here.

it would be great if I can use the summary also on cloudmade. Maybe I can override your class if you don't have time for it.

I appreciate your help

jaak
User is online Online
Joined: 06/19/2008

I updated now the libs on nutiteq.com/beta/lib to ones which parse much more data from CloudMade routing response, including summary and instruction point types and distances. Attached is image of the test app result with this.

Some specific fields are still there more, if these are needed then application should directly talk with CloudMade server, as the parameters do not fit to library generic API.

/JaakL

marshallmaster
User offline. Last seen 12 weeks 5 days ago. Offline
Joined: 04/21/2010

Works like a charm now with the new beta library.

i just received a answer from cloudmade.

the "foot" option is not yet supported for ROUTE_TYPE_MODIFIER_SHORTEST ( but i think you always want the shortest by walking) so you don't need to fill this parameter:

CloudMadeDirections cMD = new CloudMadeDirections(nutiteqRouteWaiter,nutiteqRouteWaiter.getStartCoordinates(), nutiteqRouteWaiter.getEndCoordinates(), "Foot","222c0ceb31794934a777ed9403a005d8","END-USER-ID");

see also: http://developers.cloudmade.com/wiki/routing-http-api/Documentation.