[OpenLayers-Users] Saving with a Google Maps base layer

Tom B seileef at gmail.com
Wed Jun 10 17:18:43 EDT 2009


Hi,

It turns outs that stitching together Google Static Maps images is indeed in
violation of the Google Maps ToS.  See 10.2 of:
http://code.google.com/apis/maps/terms.html

Does anyone happen to have any other ideas of how to achieve this goal
without violating the ToS?  My guess is that it's not possible, but if
anyone has any ideas about it, that'd be great.

Thanks,
Tom


Tom B wrote:
> 
> OK, this has been pretty straightforward (thanks for the tips, Gregor). 
> The one issue I'm having is calculating the latitude value of the tiles'
> centers while accounting for the change in distance per latitude degree
> while traveling north-south.  The code I'm using now calculates a
> "latitude degrees per pixel" value, which is an alright approximation for
> the whole map at very high zoom levels, but at lower zoom levels it isn't
> accurate, and the resulting tile rows begin to drift apart.  I have very
> little GIS experience, so I'm a bit lost on where to start with
> calculating these centers accurately.  
> 
> Any ideas of how to approach this?  I'm guessing that trig-related
> expressions will be involved.
> 
> To show how this is currently set up, my code is:
> 
> // $width and $height - the pixel dimensions of the map
> // $bounds - the EPSG:4326 BBOX of the map
> function add_gmaps_layer($image, $width, $height, $bounds, $zoom, $key,
> $temp_dir){
> 	$base_url =
> 'http://maps.google.com/staticmap?key='.$key.'&sensor=false&size=640x640&zoom='.$zoom;
> 	$num_cols = ceil($width/640);
> 	$num_rows = ceil($height/640);
> 	list($left, $bottom, $right, $top) = split(',', $bounds);
> 	$lon_per_px = abs($right-$left)/$width;
> 	$lat_per_px = abs($top-$bottom)/$height;
> 	for($i=0; $i<$num_cols; $i++){
> 		for($j=0; $j<$num_rows; $j++){
> 			// Calculate the tile's center, relative to the bottom right corner of
> the map
> 			$center_x = 320 + ($i*640);
> 			$center_y = 320 + ($j*640);
> 			// Calculate the lon, lat of the tile
> 			$center_lon = $right - ($center_x*$lon_per_px);
> 			$center_lat = $bottom + ($center_y*$lat_per_px);
> 			$url = $base_url.'&center='.$center_lat.','.$center_lon;
> 			$x = $width - (($i+1)*640);
> 			$y = $height - (($j+1)*640);
> 			// Blit the tile onto the main image width a displacement of $x, $y 
> 			$image = blit_from_url($image, $url, $x, $y, $temp_dir);
> 		}
> 	}
> 	return $image;
> }
> 
> 
> Gregor at HostGIS wrote:
>> 
>> Tom B wrote:
>>> Has anyone had a chance to try this out?  Gregor, any luck with getting
>>> R&D
>>> funding, by any chance?  If not, I might go ahead and take a crack at
>>> it,
>>> since it is something our map will eventually need.
>> 
>> The customer wasn't up for it when I presented it to him, so I have 
>> nothing to show on this. Sorry.
>> 
>> The way I figure to render it, would be:
>> 
>> Take image width, divide by 640 rounding up.
>> Take image height, divide by 640 rounding up.
>> foreach w in width:
>>    foreach h in height:
>>      figure up center latlng (320,320) based on bbox and pixel position
>>      figure URL
>>      fetch image
>>      blit it onto the canvas
>> 
>> I have existing code in the Wiki ("Printing" page) for doing this in 
>> PHP, using URLs that are provided by the client. That at least shows the 
>> blitting and alpha code.
>> 
>> -- 
>> HostGIS, Open Source solutions for the global GIS community
>> Greg Allensworth - SysAdmin, Programmer, GIS Person, Security
>> Network+   Server+   A+   Security+
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Saving-with-a-Google-Maps-base-layer-tp2736685p3058442.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list