comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to include a scale bar (distance bar) on the Google Map Plot?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to include a scale bar (distance bar) on the Google Map Plot? [message #90981] Wed, 20 May 2015 07:29 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

How can I include a scale bar within the Google Map plot below? (For example, I wanted something like the one at the following link: http://www.androidcentral.com/google-maps-update-brings-back -scale-bar).

Assume the Google Map plot is something similar to the following:
http://www.idlcoyote.com/gallery/google_map_plot.png

Can anyone suggest me how I can do that?



My program is as below:
----------------------------------------
PRO test_GooglePlot

CLOSE,/ALL

Lats=[51.51D,51.55D] ; deg.N
Lons=[12.91D,12.95D] ; deg E
centerLat=(MAX(Lats) + MIN(Lats)) / 2.0 ; deg. N
centerLon=(MAX(Lons) + MIN(Lons)) / 2.0 ; deg. E

zoom=14
scale=cgGoogle_MetersPerPixel(zoom)
xsize= 600 < 640 ; Max size of Google image with this Google API
ysize= 600 < 640 ; Max size of Google image with this Google API
resolution = STRTRIM(xsize,2) + 'x' + STRTRIM(ysize,2)

googleImageFilename='testgoogleimg.png'

googleStr="http://maps.googleapis.com/maps/api/staticmap?" + $
"center=" + StrTrim(centerLat,2) + ',' + StrTrim(centerLon,2) + $
"&zoom=" + StrTrim(zoom,2) + "&size=" + resolution + $
" &scale=2&maptype=satellite&sensor=true&forma t=png32 "

netObject = Obj_New('IDLnetURL')
void = netObject -> Get(URL=googleStr, FILENAME=googleImageFilename)
Obj_Destroy, netObject
googleImage = Read_Image(googleImageFilename)

mapCoord = Obj_New('cgMap', 'Mercator', ELLIPSOID='WGS 84') ; ,/OnImage
uv = mapCoord -> Forward(centerLon, centerLat)
uv_xcenter = uv[0,0]
uv_ycenter = uv[1,0]
xrange = [uv_xcenter - (xsize/2.0D*scale), uv_xcenter + (xsize/2.0D*scale)]
yrange = [uv_ycenter - (ysize/2.0D*scale), uv_ycenter + (ysize/2.0D*scale)]
mapCoord -> SetProperty, XRANGE=xrange, YRANGE=yrange
PRINT, xrange, yrange

geo_lat=[51.5256, 51.5290, 51.5296, 51.5261, 51.5269, 51.5250, 51.5256, $
51.5260, 51.5300, 51.5264, 51.5255, 51.5252, 51.5271, 51.5257, $
51.5253, 51.5249, 51.5201, 51.5220, 51.5256, 51.5260, 51.5251, $
51.5265, 51.5257, 51.5186, 51.5227, 51.5257, 51.5198, 51.5361, $
51.5263, 51.5200, 51.5350, 51.5312, 51.5187, 51.5260, 51.5260, $
51.5247, 51.5257, 51.5217, 51.5266, 51.5264, 51.5255, 51.5265, $
51.5260, 51.5252, 51.5287, 51.5277, 51.5227, 51.5251, 51.5341, $
51.5248]

geo_lon=[12.9289, 12.9264, 12.9259, 12.9223, 12.9135, 12.9254, 12.9277, $
12.9272, 12.9280, 12.9264, 12.9257, 12.9262, 12.9421, 12.9272, $
12.9272, 12.9272, 12.9410, 12.9229, 12.9254, 12.9288, 12.9373, $
12.9279, 12.9267, 12.9291, 12.9307, 12.9179, 12.9373, 12.9405, $
12.9313, 12.9202, 12.9277, 12.9350, 12.9134, 12.9264, 12.9256, $
12.9254, 12.9262, 12.9274, 12.9285, 12.9256, 12.9281, 12.9272, $
12.9280, 12.9290, 12.9200, 12.9319, 12.9273, 12.9282, 12.9167, $
12.9263]

cgPlotS, geo_lon, geo_lat, PSYM=16, SYMSIZE=2.0, MAP=mapCoord, $
THICK=2.5, COLOR='yellow'

END

test_GooglePlot

cgPS_Open,'test_googleplot.ps'
test_GooglePlot
cgPS_Close

cgPS2Raster,'test_googleplot.ps',/PNG,/Portrait, $
Width=600, DENSITY=300, RESIZE=100

END
-------------------------------------------------------

Thanks in advance,
Regards,
Madhavan
Re: How to include a scale bar (distance bar) on the Google Map Plot? [message #90982 is a reply to message #90981] Wed, 20 May 2015 08:27 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> How can I include a scale bar within the Google Map plot below? (For example, I wanted something like the one at the following link: http://www.androidcentral.com/google-maps-update-brings-back -scale-bar).
>
> Assume the Google Map plot is something similar to the following:
> http://www.idlcoyote.com/gallery/google_map_plot.png
>
> Can anyone suggest me how I can do that?

You know how many meters/pixel you have in your image (it is in the
"scale" variable). Do some simple math to figure out how many pixels
would be required to display the range you want (maybe 500 meters in
this image). Then just draw an arrow or whatever that long on your image
with cgPlotS. Use cgText to label it.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Creaty dummy.jpeg with Linux command
Next Topic: Why does IDL jump to first line of code?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:36:45 PDT 2025

Total time taken to generate the page: 0.01133 seconds