I have a custom map with custom map tiles I've created for a website. Whenever I update these map tiles and deploy them to the site, I need my users's to clear their cache of the old tiles so that they download the new tiles instead.
Since the map tiles are loaded by JavaScript, you can't simply force your users to get new files with a SHIFT-Refresh.
The only method I can think of so far is to change the folder name that the tiles are loaded from. Something like:
tiles-20121125 <--- todays date
So every time the tiles are updated, I simply change the folder name to a new name, forcing the visitors to download new tiles.
Is there a better way? Something built into the Google Maps v3 API maybe?
Browsers cache the image data based on the requested url, which is as well as the ajax cache.
Google Maps API doesn't offer any methods to do that.
So the most easiest way, you can append the version as query parameter.
function getTileUrl(point, number) {
return "http://your.server.com/tiles/" + point.x + "_" + point.y + ".png?v=20121125"
}
Then Google Maps API loads image data from the URL.
The mechanism to load the image might be:
var img = new Image();
img.src = tile_url;
Something like that.
(Actually Google Maps API uses canvas tag instead of Image recently)
Related
String url = "http://maps.google.com/maps/api/staticmap";url
+= "?zoom=13&size=" + width + "x" + height;url
+= "&maptype=roadmap";url
+= "&markers=color:red|label:A|"
+ lat
+ ","
+ lon; url
+= "&sensor=true";
My first attempt was to get a static map with my center location and my zoom level and it worked but when I'm adding markers to the URL I'm getting the same image but no markers.
I'm doing exactly the same from the Google Map API Doc but i cant figure out whats wrong.
Is there any other way to show map in j2me application??
There are fundamentally two ways to show maps in a Java ME application. Your method of making an HTTP request to a map server is best suited to situations where all you need is one single map image. Since each map update will require more network traffic. If you need a series of images, add custom markers or you want to dynamically update the map, you would be much better off using a dedicated library which uses a tile server, caches your map tiles and overlays objects on top of it. The reasoning behind this is described here
The dynamic mapping library I would recommend is the HERE Maps API for Java ME, as you can tell from the name, the API is specifically designed to work with Java ME devices.
The API is currently bundled with the Nokia Asha SDK 1.0, but despite this, it is in reality a separate independent plugin and has been designed to work with the full range of standard Java ME devices.
A similar Stack Overflow question answered here describes how to download it.
The code to display a marker on the map can be found in the Developer's Guide
map.setState(new MapDisplayState(new GeoCoordinate(51.477, 0.0, 0), 15));
MapStandardMarker marker = mapFactory.createStandardMarker(
new GeoCoordinate(51.477, 0.0, 0), 10, "Hi!",
MapStandardMarker.BALLOON);
marker.setColor(0xFFFF0000); // Color is red
map.addMapObject(marker);
As a notice of affiliation, I should mention in passing that I do work for Nokia.
I'm writing an application where user can point a position in a Google Maps map (using Google Maps API).
I grab the position by:
google.maps.event.addListener( my_map, 'click', function(mouseEvent){
var position = mouseEvent.latLng;
//position = 41.57187486787156, 0.609094047546364
});
Then, in an another page, I display an image with all marked positions using Google Static Maps using the coordinates grabbed from user marked points:
<img alt="map image" src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=550x380&markers=label:A|41.57187486787156, 0.609094047546364">
Google Static Map displays the marker a little to the south.
Static Maps has a precision-limit of 6 decimals for locations, the marker-position will be rounded and set to 41.571875,0.609094
You'll need to round the values inside the dynamic map too to get the same marker-location on both maps.
Static means "constant--never changing".
dynamic is "changing". You can make dynamic changes to a database without having to shutdown the instance and restart for the changes to take effect. However, if you do not update the control file, when you shutdown and startup, the dynamic change is gone--it wasn't permanent.
Static sites are meant for those sites that cant be changed or updates regularly.
and Dynamic sites are those sites that changes or update regularly.
I have a batch of high definition images, and I want to make use of technologies like google maps to view the images, user can use zoom pan to zoom in and out quickly without downloading the whole big picture file(they only need to download the viewport of the big image).
How can I do this?
Thanks.
Bin
If the image in question is actually a map or something that can be reasonably overlaid onto a map, use MapTiler (http://www.maptiler.org/) to split it into tiles, then use code like this to display the tiles:
var lat=37.767569;
var lon=-122.392223;
var initialZoom=17;
var tileDir = 'tiles_dir';
var mapTypeId = 'Your Custom Map';
var mapType = new google.maps.ImageMapType({
tileSize: new google.maps.Size(256,256),
getTileUrl: function(coord,zoom) {
return "img/"+tileDir+"/"+zoom+"/"+coord.x+"/"+coord.y+".png";
}
});
var map = new google.maps.Map(document.getElementById("map_canvas"),
{center:new google.maps.LatLng(lat,lon),
mapTypeId:google.maps.MapTypeId.ROADMAP,
zoom:initialZoom,
mapTypeControl:false});
map.overlayMapTypes.insertAt(0, mapType);
map.mapTypes.set(mapTypeId, styledMap);
map.setMapTypeId(mapTypeId);
Note that Map Tiler sets the image name to something Google Maps API v2 specific. If you are using v3 (and you should!) you'll have to take each file name (e.g., 2001.png), and move it to a file name that's good for v3. To do that on Linux or a Mac, cd to the tiles directory and run this script (note that the script assumes you are in the tiles dir!):
#!/bin/bash
tiles=`ls -d */*/*`
for thisPath in $tiles
do
thisFile=${thisPath#*/*/}
oldY=${thisFile%.png}
zoomX=${thisPath%/*}
zoom=${thisPath%/*/*}
newY=$(((1<<zoom) - oldY - 1))
mv ${zoomX}/${oldY}.png ${zoomX}/${newY}.png
done
Now, even if your image is not actually a map or something that would be reasonably overlaid on a map, hopefully this gives you some ideas of where to look and what to poke around with if you want to leverage Google Maps. (There may be tools out there to let you easily build this type of functionality without Google Maps, but if so, I have no experience with them.)
There's Google Maps, of course. I'm totally serious: GMaps API allows you to create custom map types, you'll need to give it a way to show the "tiles" (parts of your image) at a given zoom level.
The most work I'd assume would be in creating the "tiles" from your image at various zoom levels (split the image into smaller rectangles), but I suppose that can be automated. The UI, dragging, zooming and whatnot is then handled by the JavaScript script of Google Maps.
(this works, I've made a boardgame with such custom tiles, using Google Maps as the underlying framework for showing it.)
I've just found this library, which is quite slick: http://polymaps.org/
I'm currently using the Google Maps v.3 API to generate a custom map of locations in my database on my site. Each location that turns up in the database query is given a marker and a simple Info Window that displays its name and address. However, I'd like to give users the option of also looking at the map on Google's site (maps.google.com) so that they can access driving directions there. Is there any way to do this? I was thinking something the along the lines of dynamically importing a GeoRSS feed, but I don't know if that's possible.
Users can click on the Google Logo on the bottom left hand side of the map to go to a standard google maps page.. alternatively can build up a URL from your map and send them off to a new page.. here's a function I use to give Users a URL that they can paste into other places.. you could use similar code with the window.open javascript function:
function GenerateLink(){
var url;
url = "http://maps.google.com/?ll=" + map.getCenter().lat() + "," + map.getCenter().lng() + '&z=' + map.getZoom();
prompt("You can copy this link using CTRL-C, its a direct link to Google Maps for the current map center and zoom level", url);
}
Duncan.
Usually u have to set up a little script + htmlpage on your server to run google maps,
but i was wondering - is it possible to use google maps directly?
i mean by just calling an url with parameters (gpoint coordinates, zoomfactor ..) and it loads the map fullscreen without having to use my own server?
Sounds like you might be after the static maps api. You can build a URL specifying the properties of the map like:
zoom
position
markers (including custom markers)
image size
etc
and you will get back a rendered image of the map. Something like:
Obviously this just gives you a fixed image of the map you are after. If you need a dynamic Google map, then you will need to use the Google Maps Javascript API.
Not hosted by Google. You might find some other website that uses the API to do the same thing.
Google Maps API