How to retrieve individual tile images using Google Maps API?
Using the Google Maps Static Map API, I'm able to enter a location and retrieve a single composited image at a specified zoom level.
I'm int开发者_开发问答erested in adding a dynamic scrolling/zooming interface — how can I use the Google Maps API to retrieve individual map tile images around a specified location and zoom level?
For example, if I use a DOM inspector when visiting http://maps.google.com/, I can pick out a 256x256 tile image such as this:
https://mts1.google.com/vt/x=2227&y=3120&z=13
How can I calculate values for the x
and y
parameters in that URL?
Short answer is, you shouldn't. From the FAQ:
Can I access the Maps and Satellite images directly?
You may not access the maps or satellite images through any mechanism besides the Google Maps APIs (such as the creation of your own mapping API or the use of a bulk tile download script). Your application's access to the tiles will be blocked if it accesses them outside of the Google Maps APIs. See section 10.1.1.a of the Google Maps Terms of Service for more details.
And in case the threat of getting blocked isn't enough, any system you come up with yourself will sooner or later break when Google changes the internal URL without warning.
Use the following java code:-
String temp;
Image image = null;
temp="http://maps.googleapis.com/maps/api/staticmap?center="+latitude+","+longitude+"& zoom=18&size=100x100&sensor=false&maptype=satellite";
URL url = new URL(temp);
image = ImageIO.read(url);
ImageIO.write((RenderedImage) image, "jpg",new File("D:\\map.jpg"));
// give the latitude and the longitude as 25.165173,47.237548
And run the code you will the image of an area in Saudi Arabia.
I think it would be useful.
Must you use Google Maps? OpenStreetMap, http://wiki.openstreetmap.org/wiki/Tiles, might have more lenient terms of service and be easier to query for the tiles.
精彩评论