PApplet in Android mode

I’m unable to use this function in the processing for android mode, because it’s first argument requires PApplet

StaticMap m = new StaticMap(this, new com.modestmaps.providers.Microsoft.RoadProvider(), new Point2f(width/2, height), new com.modestmaps.geo.Location((float)currentLatitude, (float)currentLongitude), 16);

If I pass in this it’s just going to crash with the following error message:

FATAL EXCEPTION: Animation Thread
Process: processing.test.maps_go, PID: 4386
java.lang.RuntimeException: Missing renderer class
	at processing.core.PApplet.makeGraphics(Unknown Source)
	at processing.core.PApplet.createGraphics(Unknown Source)
	at com.modestmaps.StaticMap.render_tiles(StaticMap.java:225)
	at com.modestmaps.StaticMap.draw(StaticMap.java:199)
	at processing.test.maps_go.Maps_Go.draw(Maps_Go.java:94)
	at processing.core.PApplet.handleDraw(Unknown Source)
	at processing.core.PSurfaceNone.callDraw(Unknown Source)
	at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

How can I get the render class, and which one should I get?

Thanks in advance.

EDIT: This is the link to the library’s github: https://github.com/RandomEtc/modestmaps-processing

1 Like

Last time modification of this lib was about 7 years ago.

Try unfolding maps and see if it works in Android mode. Or you could launch a webView and use something like mapBox.

Kf

Thanks for your response, but before it crashes, it loads images, so that’s working. The only problem is that it can’t draw on the non PApplet class…

I’m wondering if there’s a way to get sketch variable from Mainactivity.java in my sketch, so I can use it instead od this, it’ll probably work.

EDIT: Unfolding maps are only for Processing 2, but I’m using Processing 3 with Android mode.

Ok, I’ve forked original library, patched it and requested a pull, it’s working now.

Thanks for your help :smiley: @kfrajer

1 Like

Very neat. Do you mind sharing a link to your repo for the time being? Not sure how fast the pull req will go through. In the time being, other ppl could benefit by using your version.

Kf

I don’t mind, but do keep in mind that I’ve only made it work, and haven’t optimized or improved anything at all, most of the stuff could still be broken.

Link to the github repo

1 Like

Fair warning. My thoughts are that the more ppl trying it, the better lol Although I would prefer ppl working from the original repo. Let’s hope the repo admin accepts the pull req soon. Thxs.

Kf

No problem, to be honest, I love tinkering and improving libraries, so I’ll probably do that in my free time, or maybe that’s something that the original GitHub devs will do instead.

Thanks for the kind words :wink:

1 Like

I’m using modestmaps on processing/android. I tried Unfolding but it didn’t work - screen just flickered and flashed like it was using too much memory… To get modestmaps to work I had to stick the entire source into my android studio project and edit. There was one line of code I changed. I had no idea what it did, but it worked.

@HackinHarry What version of unfolding were you using? Did you use the P3D renderer? Can you post your code reproducing your problem?

I believe you could explore mapbox or google maps as alternatives. Some code might be on the older forum.

Related to modestmap, are you referring to this? Related post https://forum.processing.org/one/topic/modest-maps-android-help-me-fix-error.html

Kf

1 Like

For modestmaps, I put a com directory in src and then put the modestmaps source directory and I edited the class TileLoader (InteractiveMap.java) because PImage wants a single argument instead of two. I also had to edit “boolean smooth = p.g.smooth;” up around line 80 because p.g.smooth is an int and needs to be true or false. I took a wild guess that true is good.

 public class TileLoader implements Runnable {
    Coordinate coord;

TileLoader(Coordinate coord) {
  this.coord = coord; 
}
public void run() {
  String[] urls = provider.getTileUrls(coord);
 // PImage img = p.loadImage(urls[0], "unknown"); // use unknown to let loadImage decide
	PImage img = p.loadImage(urls[0]); // use unknown to let loadImage decide
  if (img != null) {
    for (int i = 1; i < urls.length; i++) {
    //  PImage img2 = p.loadImage(urls[i], "unknown");
		PImage img2 = p.loadImage(urls[i]);
      if (img2 != null) {
        img.blend(img2, 0, 0, img.width, img.height, 0, 0, img.width, img.height, BLEND);
      }
    }
  }
  tileDone(coord, img);
}

}

As for Unfolding, I’ll have to play with it again to see what was not working right and which version I tried.

2 Likes

@HackinHarry Thxs for sharing your comments. Could you please edit your post and format your code? To format, select your code and hit the </> button in the toolbar in the post text box.

Kf

You can use my version of modest maps. I’ve changed all of that and made it work. I’ve posted link to repo above.

1 Like