Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass jQuery input values to Google Maps JS API v3?
    primarykey
    data
    text
    <ul> <li><p>1: I have a Google maps code for styling and have some <strong>user input controls</strong> such as text box, combo box which are using jQuery coding on the same page of the map. Now I want to pass input users such as <strong>featureType</strong> or <strong>MapType</strong> to initialize function of Google maps which is in Javascript as well. I don't know how to connect these two parts. They work correctly separately. I am quite new in jQuery :).</p></li> <li><p>2: The 2nd problem is that I don't know where exactly I should locate jQuery code, in Head or Body, because my Google maps JS code is in the Head.</p></li> </ul> <h2>Here is the Google Maps Code:</h2> <pre><code>&lt;head&gt; ... &lt;script type="text/javascript"&gt; function initialize() { // map style default var pinkParksStyles = [ { featureType: "road", // or e.g: "road.highway" or "road.local" or "poi.medical" elementType: "all", // or "geometry" or "labels" stylers: [ { hue: "#ff0000" }, { saturation: -5 }, { lightness: -34 }, { gamma: 1.16 } ] } ]; var myOptions = { zoom: 12, center: new google.maps.LatLng(55.753395,37.62394), mapTypeId: google.maps.MapTypeId.ROADMAP // other mapType: Hybrid, Terrain, Satellite }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); map.setOptions({styles: pinkParksStyles}); } google.maps.event.addDomListener(window, 'load', initialize); &lt;/script&gt; &lt;head&gt; </code></pre> <p>And here is jQuery input labels, I tested them through alert.</p> <h2>jQuery Input controls</h2> <pre><code>&lt;body&gt; ... &lt;div id="map_canvas" style="width:700px; height:500px"&gt;&lt;/div&gt; // show the map &lt;form&gt; &lt;label for="saturation"&gt; Type a Number between -100, 100: &lt;/label&gt; &lt;input id="saturation" type="text" /&gt; &lt;input type="button" value="Show Value" onclick="alert( $('#saturation').val() )" /&gt; &lt;/form&gt; &lt;form&gt; &lt;select id="mapTypeId"&gt; &lt;option value="1"&gt;Hybrid&lt;/option&gt; &lt;option value="2"&gt;Terrain&lt;/option&gt; &lt;option value="3"&gt;Satellite&lt;/option&gt; &lt;/select&gt; &lt;input type="button" value="Show Value" onclick="alert( $('#mapTypeId').val() )" /&gt; &lt;/form&gt; &lt;form&gt; &lt;select id="featureType"&gt; &lt;option value="1"&gt;all&lt;/option&gt; &lt;option value="2"&gt;road&lt;/option&gt; &lt;option value="3"&gt;water&lt;/option&gt; &lt;/select&gt; &lt;input type="button" value="Show Value" onclick="alert( $('#mapTypeId').val() )" /&gt; &lt;/form&gt; ... &lt;/body&gt; </code></pre> <p>I just know should use something like this: </p> <pre><code>var featureType = $("#featureType").val(); </code></pre> <p>but don't know how to send it to G maps JS code and where locate jquery.</p> <hr> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload