2

I am showing a static map in the mobile device. Code for getting the map is:

http://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&zoom=13&size=600x300&sensor=false

Now my issue is with the attribute size. That is with the width & height

My application is a J2EE application. So, in the main JSP i have set the viewport as follows:

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />



But I dont know how to set the width and height in another JSP. It is as follows:
-->>> Here i have hardcoded to 600x300. how to set height & widht dynamically here

<img src="http://maps.googleapis.com/maps/api/staticmap?center=<c:out value="$cityName"/>&zoom=<c:out value="$zoomSize"/>&size=600x300&sensor=false">

Any idea ?

smilyface
  • 5,021
  • 8
  • 41
  • 57
  • I am unfamiliar with jsp but would it not be possible to insert a variable into the size parameter like so: &size= and set the size variable using a switch statement prior to map instantiation? – ChrisSwires Jan 29 '14 at 11:01
  • @Swires , actually my question is: How to GET the size (width and height) and how to SET it to the image ? I know JSP. The thing is I am not aware of getting the viewport size in digit – smilyface Jan 29 '14 at 11:03
  • Get the size of the map? You're setting that yourself. Without the size parameter no map is served. The simplest way to set the size would in fact to simply request a higher resolution image than you need and resize the div that it is contained within using CSS. More infor available here: https://developers.google.com/maps/documentation/staticmaps/#Imagesizes – ChrisSwires Jan 29 '14 at 11:06
  • see , there HOW i will get the values. For example - 640x640 , 400x50 etc. Now i am getting the output as image with hardcoded size. I need to get the sizes (screen width and screen height of viewport) dynamically. It will be different for diffenent mobile devices, right ? – smilyface Jan 29 '14 at 11:09
  • The device shouldn't matter, you need to access the browsers window object. See examples post below, unsure as to what language you're looking for. – ChrisSwires Jan 29 '14 at 11:22

1 Answers1

3

If you have access to client side Javascript in your application then you can use:

// attempt to get the size from the window object
// otherwise fallback to the document body. 
var size = {
  width: window.innerWidth || document.body.clientWidth,
  height: window.innerHeight || document.body.clientHeight
}

If you're looking to find a server side solution in java(?) then see here for an example.

Community
  • 1
  • 1
ChrisSwires
  • 2,713
  • 1
  • 15
  • 28