Following are the Java ME code examples to use different map sources usign MGMaps Lib SDK. Map image previews are here. Pre-requirement for all is that new MapComponent or MapItem object called map is created.
map.setMap(new CloudMade("YOUR-CLOUDMADE-KEY",
64, 1279));map.setMap(new NutiteqStreamedMap( "http://aws.nutiteq.com/mapstream.php?cmkey=YOUR-CLOUDMADE-KEY&ts=128&", "CloudMade", 128, 0, 19));
map.setMap(new QKMap("Bing","http://ecn.t1.tiles.virtualearth.net/tiles/r",256,0,19,".png?g=461&mkt=en-us&shading=hill&n=z"));map.setMap(new QKMap("Microsoft",
"http://ecn.t2.tiles.virtualearth.net/tiles/h", 256,
1,17, ".jpeg?g=321&mkt=en-us"));map.setMap(new BlomOrthoMap("YOUR-BLOM-KEY",
BlomOrthoMap.NORTH));GeoMap blom = new BlomOrthoMap("YOUR-BLOM-KEY",
BlomOrthoMap.ORTHO);
blom.addTileOverlay(new
BlomStreetsOverlay("YOUR-BLOM-KEY"));
map.setMap(blom);GeoMap mapdg = new DigitalGlobeMap("YOUR-DG-KEY");
mapdg.addTileOverlay(new OsmOverlay());
map.setMap(mapdg);
map.setMap(new NutiteqStreamedMap( "http://aws.nutiteq.com/dgstream.php?key=YOUR-DG-KEY&", "DigitalGlobe", 64, 0, 21));
map.setMap(new OpenAerialMap(1,19));
map.setMap(new NavteqMapTP("YOUR-MAPTP-KEY"));
map.setMap(new JaredOpenStreetMap(256, 1, 11));
SimpleWMSMap wms = new SimpleWMSMap( "http://iceds.ge.ucl.ac.uk/cgi-bin/icedswms?VERSION=1.1.1&SRS=EPSG:4326", 256, 0, 18,"bluemarble,cities,countries", "image/jpeg", "default", "GetMap", "© UCL"); wms.setWidthHeightRatio(2.0); mapComponent.setMap(wms);
Not directly. Currently you would need also a server solution to generate raster map tiles from the Shapefiles: e.g. ESRI ArcIMS, MapServer or some other.
Vector maps in client is something we are working on, it's not yet available. However, in most cases server-based rendering is better, as servers are more powerful and you can get much nicer maps with this approach. Also some map vendors may not allow to distribute their vector data in client side.
How do I use My own WMS Map Service? is it enough to use :
SimpleWMSMap wms = new SimpleWMSMap(
"http://iceds.ge.ucl.ac.uk/cgi-bin/icedswms?VERSION=1.1.1&SRS=EPSG:4326",
256, 0, 18,"bluemarble,cities,countries", "image/jpeg",
"default", "GetMap", "© UCL");
wms.setWidthHeightRatio(2.0);
mapComponent.setMap(wms);
Here, "bluemarble,cities,countries" are layers for maps, what should i have to do if i am using my own maps and lets say i don't know the layers. What is the default parameter to write?
I tried to implement with own wms maps but it says the following error:
1. msWMSLoadGetMapParams(): wms server error.
2. Invalid layer(s) given in the LAYERS parameter.
It seems that your WMS server does not accept request parameters. It could be LAYERS, or also some other parameter. I suggest to check out final URL (using e.g. network monitor or WTK emulator), and try to get it working with changing parameters properly. You can post the final URL here also, so I could take a look.
hi,
I'm using SimpleWMSMap, and able to set my Map.
can I give any value other than the default/"" for 'style' parameter,i.e., the seventh one in SimpleWMSMap constructor.
now I'm giving "" , I'm getting BIG letters on my Map. what shall I do to reduce the size of the letters?
You can use any value what your server accepts. It depends on server implementation and configuration. "Default" is common default value for ArcIMS-based servers, some others prefer empty value here.
Hi,
This is my URL that I am requesting:
http://ar22.arbonaut.com/cgi-bin/mapserv.exe?map=D:/webpages_taaka/taaka...
Thank You.
I tried following code, and it worked for me. Note that you must use EPSG:4326 and cannot use 3067 like in your example URL. Your server seems to support also EPSG:4326.
SimpleWMSMap wms = new SimpleWMSMap("http://ar22.arbonaut.com/cgi-bin/mapserv.exe?map=D:/webpages_taaka/taaka/wmscapabilities_matintesti_modis.map&VERSION=1.1.1&&SRS=EPSG%3A4326&SERVICE=WMS&",
256, 0, 18, "topo", "image/png","", "GetMap", "");
wms.setWidthHeightRatio(2.0);
map.setMap(wms);
Hi,
It worked for me.
Thanks
If I have a image and I know it's four corner coordinates, is there a chance to use it as a map? It is just a school project so I don't need something accurate.
In principle it should be possible. Technically it requires that you convert image to the 256x256 tiles, in specific coordinate system. How do you want to use it, bundled with application (off-line), or using an on-line server? If you can give the image and coordinates then it could give better idea how this could be solved. Maybe we could suggest or provide you tool to do necessary conversions.
ClujMap
The image is too big to be uploaded (about 10MB).
If I could send it to you on skype would be great. If it's just to put the maps on a local server, It doesn't matter their location (offline or online).
Thank you very much.
You can send it to skype user nutiteq. 10MB is too big bundling into application JAR, but it really depends on many factors.
I wrote to you on skype
Thank you
WOW!!!
I works!
You are realy great!
The only problem is that I don't know why is not loading all the tiles as you could see in the image:
Map
Anyway, it should be enough for the project I have. I appreciate your fast replys and I will recomend you wherever I'll have the oppurtunity.
Hi,
I can't use my own mapserver.
this my sample code.
package com.tutorial;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import com.nutiteq.MapItem;
import com.nutiteq.maps.*;
import com.nutiteq.components.WgsPoint;
import com.nutiteq.controls.ControlKeys;
import com.nutiteq.components.Place;
import com.nutiteq.components.Line;
import com.nutiteq.components.Point;
import com.nutiteq.components.LineStyle;
import java.io.IOException;
public class HelloMap
extends MIDlet
implements CommandListener {
private Form mMainForm;
private MapItem mapItem;
private Image icon;
public HelloMap() {
mapItem = new MapItem("Map", "tutorial", this, 300, 400, new WgsPoint(69.3234345, 41.234423), 8);
mapItem.defineControlKey(ControlKeys.MOVE_UP_KEY, Canvas.KEY_NUM2);
mapItem.defineControlKey(ControlKeys.MOVE_DOWN_KEY, Canvas.KEY_NUM8);
mapItem.defineControlKey(ControlKeys.MOVE_LEFT_KEY, Canvas.KEY_NUM4);
mapItem.defineControlKey(ControlKeys.MOVE_RIGHT_KEY,Canvas.KEY_NUM6);
SimpleWMSMap wms = new SimpleWMSMap("http://217.29.118.23:8888/cgi-bin/mapserv.exe?map=f:/OSGeo4W/secure_maps/uzbekistan.map&VERSION=5.4.2&&SRS=EPSG%3A4326&SERVICE=WMS&",
256, 1, 15, "", "","", "GetMap", "");
wms.setWidthHeightRatio(2.0);
mapItem.setMap(wms);
mMainForm = new Form("Hello map");
mMainForm.append(new StringItem(null, "Hello, map!\n"));
mMainForm.append(mapItem);
mMainForm.addCommand(new Command("Exit", Command.EXIT, 0));
mMainForm.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(mMainForm);
mapItem.startMapping();
// mapItem.addPlace(new Place(1, "Tashkent", icon, 69.3234345,41.334423));
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
/* String label=c.getLabel();
if(label.equals("OK")){
mapItem.addPlace(new Place(1, "Tallinn", icon, 69.3264580, 41.237420));
}
*/
notifyDestroyed();
}
}
How can use my own mapserver?
In my project .
following error:
1. msWMSLoadGetMapParams(): wms server error.
2. Invalid layer(s) given in the LAYERS parameter.
The SimpleWMSMap() method has parameter layers and you have left it empty. UWM MapServer requires some of the defined layers to be specified in WMS requests.
I don't know how to set parametr layers.
What this parametrs mean?
Where I can take this parametrs?
Can you send me simples like that examples?
It depends on your mapserver configuration. You have the .map file and there are layers. One (or several) of these must be given in the map request also.
Hi?
I want to use my own map of a town.
It will be bundled with the application
How do i go about with it?
Did you take a look to http://www.nutiteq.com/content/mobile-map-mapcruncher ? Basically you can use MSR Mapcruncher to create map files, then you copy maps (directory Layer_NewLayer from MSR output) to the application /res directory
Code to activate the map would be something like:
mapItem.setMap(new MyQuadKeyMap("/"));
Note that MapCruncher creates map tile images for different zooms, also resampled images. Therefore package from single large image could be quite big (many MB), which could be larger than mobile's limitation. For example I got from 1.1 MB image 10 MB of tiles. You can reduce map package by removing resampled tiles, as SDK 1.1 version can itself resample map for one zoom level.
I have used mapcruncher but i still cant get to view the map,the size of the jar file is 1.12MB am only seeing a red image,i dont know what it might be the problem,anybody can help me figure out.
The issue is probably in the project setup and code, not in the image. You need to be sure that the map view is centered to the area where you have map. And you need to be sure that tile locations are pointed correctly.
The size of my image is 23.3kb can i send it to you
Hello,
Can I display the shapefile which I added using Geoserver using hellomap example of MGmaps??
Really appreciate your help!
Thanks in advance!
Yes, you can use Geoserver to provide WMS or tile-based map service, use your shapefile as data source in the server, and then Nutiteq library to display the map on mobile.
Hi,
I have created shapefiles and displayed it using geoserver. Now, I need to access these layers(shapefiles stored in geoserver) using hello map midlet. How can I dot this..?
Thanks in advance!!
GeoServer has WMS API, so the "WMS map service" code snippet example above should give hint. You should just replace parameter values: server and layer names with your server's.
hi,
I created a shapefile called 'india shp' in geoserver. I need to view this using the hello map midlet. I tried to follow the "WMS map service" code snippet and my url is: "http://localhost:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=india-shp&styles=&bbox=68.178,6.734,97.462,37.035&width=494&height=512&srs=EPSG:4326&format=application/openlayers"
but i get an error saying: cannot find symbol
symbol : class SimpleWMSmap
location: class com.tutorial.HellMap
SimpleWMSMap wms = new SimpleWMSmap("http://localhost:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=india-shp&styles=&bbox=68.178,6.734,97.462,37.035&width=494&height=512&srs=EPSG:4326&format=application/openlayers",256,0,18,"india_st,india_water,india_natural,india_coastline,india_highway,india_ds","image/jpeg","default","GetMap","");
1 error
Can you please let me know the correct code to implement, and debug my error?
thanks in advance!!
Perhaps you have not added proper import to the class (import com.nutiteq.maps.SimpleWMSMap;)
i have added the import. it works now i am not getting any error.but..
I have posted a part of the code i used in my example below. The layers of my india-shp file are-india_st,india_ds,india_coastline,india_natural,india_water and india_highway.
code:
private MapItem map;
public HellMap() {
SimpleWMSMap wms = new SimpleWMSMap("http://localhost:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=india-shp&styles=&bbox=68.178,6.734,97.462,37.035&width=494&height=512&srs=EPSG:4326&format=application/openlayers",256,0,18,"india_st,india_water,india_natural,india_coastline,india_highway,india_ds","image/openlayers","","GetMap","");
wms.setWidthHeightRatio(2.0);
map.setMap(wms);
}
can you please let me know if the code written above is correct?
And also, when i execute my example it doesn't give any error, the emulator opens but when i try to launch my application it gives me an exception saying- the application has unexpectedly quit. Contact the application provider to resolve the issue.
I am not able to display the map. I did keep my geoserver started and even tried giving the website address in the emulator but it still gives me the same exception. please tell me where am i going wrong.
thank u!!
In this code two specific things looks wrong:
1) Map size in request should be tile size, by default 256 pixels. So instead width=494&height=512 use width=256&height=256
2) Use IP of the map server instead of "localhost". It may work with localhost on (some) emulators, but with real devices and in most emulators "localhost" means phone itself, not your computer host what you probably mean here.
Hello,
I and Anjana are working on the same topic. Even I am facing the same problem. I changed the Map size to 256 and used IP address as 127.0.0.1 but its still giving the same exception.
Thanks!
hello,
ya..i agree with shamitha.its still giving the same exception....please specify a solution to this problem....
thank u!
Hi,
I was trying to figure out why an exception saying-"the application has unexpectedly quit. Contact the application provider to resolve the issue." is getting displayed on an emulator. Then I thought may its because, I have not added the MG maps evaluation key. Can u please tell me where I should include this key.
Thanks in advance!!
The exception probably has nothing to do with mapping library, it is general application issue. You can test it by removing (commenting out) map-related lines and check if the app works fine. If you send your project to support@nutiteq.com, we can take a brief look.
MGMaps SDK key should be generated at http://www.nutiteq.com/generate_key.html , and the value should be put to MapItem object constructor parameter. However, if this is wrong then you should see empty map with message something like "license error", and not get exception.
Hi,
Thanks for the reply. I tried to take out the comment of the following instruction.
mapItem = new MapItem("Map", "eecca5b6365d9607ee5a9d336962c5344bc292103431f5.83161285", this, 300, 150, new WgsPoint(24.764580, 59.437420), 0);
Now, when i executed the code it dint show an exception but it dint display maps from geoserver.
This is the entire code:
package com.tutorial;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import com.nutiteq.MapItem;
import com.nutiteq.maps.*;
import com.nutiteq.maps.SimpleWMSMap;
import com.nutiteq.components.WgsPoint;
import com.nutiteq.controls.ControlKeys;
public class HelloMap
extends MIDlet
implements CommandListener {
private Form mMainForm;
private MapItem mapItem;
public HelloMap() {
mapItem = new MapItem("Map", "eecca5b6365d9607ee5a9d336962c5344bc292103431f5.83161285", this, 300, 150, new WgsPoint(24.764580, 59.437420), 0);
SimpleWMSMap wms = new SimpleWMSMap(
"http://127.0.0.1:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=india:india_st&styles=&bbox=68.359,6.734,97.462,37.035&width=491&height=512&srs=EPSG:4326&format=application/openlayers",
256, 0, 18,"layer_st", "image/jpeg",
"default", "GetMap", "");
wms.setWidthHeightRatio(2.0);
mapItem.setMap(wms);
mMainForm = new Form("Hello map");
}
public void startApp() {
mMainForm.append(new StringItem(null, "Hello, map!\n"));
mapItem.startMapping();
mapItem.defineControlKey(ControlKeys.MOVE_UP_KEY,Canvas.KEY_NUM2);
mapItem.defineControlKey(ControlKeys.MOVE_DOWN_KEY, Canvas.KEY_NUM8);
mapItem.defineControlKey(ControlKeys.MOVE_LEFT_KEY, Canvas.KEY_NUM4);
mapItem.defineControlKey(ControlKeys.MOVE_RIGHT_KEY, Canvas.KEY_NUM6);
mapItem.defineControlKey(ControlKeys.ZOOM_IN_KEY, Canvas.KEY_POUND);
mapItem.defineControlKey(ControlKeys.ZOOM_OUT_KEY, Canvas.KEY_STAR);
mMainForm.append(mapItem);
mMainForm.addCommand(new Command("Exit", Command.EXIT, 0));
mMainForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(mMainForm);
mapItem.startMapping();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}
}
Hi
i tried commenting out the lines as you have specified...but as shamita said, it does not display the map..and also, the emulator specifies whether to access the airtime or not..but since ours is an offline server we shouldn't be accessing the network..and even if we specify the 'yes' option,it displays a blank page with no map.
Can you please look at the code above and give us a solution...its a college project and we have to demonstrate the completed project next week. We have configured the server, understood the client side and tried it with online openstreet maps,but we need to integrate these two in order to complete the project....so...
thank you.....
hello again
i just needed to know whether we need to publish our geoserver on the internet in order to access the shapefiles present in them using the SimpleWMSMap constructor, for map display. i.e., do we have to put our geoserver on the internet using a domain name or iP address?and use this iP of the geoserver in our uRL provided in the constructor of the SimpleWMSMap?
thanks in advance!!
Yes, the geoserver has to be accessable at least from thenetwork where is client device (emulator or actual phone).
Hello,
The geoserver which we have configured has to run in offline mode in localhost. We have to access this using the hellomap application. We used the code for the simple wms map as mentioned above. But it is not working. We even tried giving ip address as 127.0.0.1. We also tried giving my computers ip address which accesses internet. But we keep getting an error saying "Network Error".
This is the code snippet:
mapItem = new MapItem("Map", "eecca5b6365d9607ee5a9d336962c5344bc292103431f5.83161285", this, 300, 150, new WgsPoint(24.764580, 59.437420), 0);
SimpleWMSMap wms = new SimpleWMSMap(
"http://172.16.0.207:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=india:india_st&styles=&bbox=68.359,6.734,97.462,37.035&width=491&height=512&srs=EPSG:4326&format=application/openlayers",
256, 0, 18,"layer_st", "image/jpeg",
"default", "GetMap", "");
wms.setWidthHeightRatio(2.0);
mapItem.setMap(wms);
Can you please give us the actual code to implement this.
You use WTK emulator? What does HTTP monitor of it shows?
Yes. We use Java ME SDK version 3. It has emulator with CLDC configuration.
When we run the application on emulator, it shows network error, even though Geoserver is started.
There could be many reasons for networking to fail: wrong IP, firewall, proxy config, blocked ports etc. None of these has anything to do with this thread (different map sources).
You need two network connections: to your map server and to Internet (SDK makes also request to lbs.nutiteq.com). This could also give networking errors.
Hello,
Solved the problem. Map is getting displayed in the emulator now. But the whole map is not getting displayed. In goeserver, when maps are displayed using openlayers, there is automatic zooming and panning on the displayed map. In midlet we have used png format so in emulator, panning works fine as we had coded in the hello map midlet. But we are not able to view the zoomed maps.
Do we need to use any other tool such as map- cruncher??
You have to define action buttons for zoom in and zoom out, then it should work. In MapItem there are default keys 1 and 3 for ths.
Thanks for the reply!!We have defined the action buttons for zoom in and zoom out. We have used zoom-in:KEY_POUND and zoom-out:KEY_STAR.
We have two problems:
1.Map is not getting loaded fast. So should we use RMSCache or streamed maps as a solution for this?
There is a caching technique in geoserver called GeoWebCache. GeoWebCache works as a proxy between your client(emulator) and GeoServer.
So in order to use this, it is specified that we have to use:
http://example.com:8080/geoserver/gwc/service/wms
instead of this:
http://example.com:8080/geoserver/wms
But when we used this in SimpleWmsMap constructor it is not loading the map, instead displays red tiles.
2.Zooming option is not working. When map is zoomed it gives blurred image rather than displaying subsequent layer details.
Can you please specify the solution for this.
Can i use a map from ArcGIS i.e ESRI shapefile