Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display some positions in map
    text
    copied!<p>How can i have some postitions in a map based is multi input values e.x:</p> <p>I use this script to obtain a map which i display later in a div.</p> <pre><code>$(document).ready(function() { //------- Google Maps ---------// // Creating a LatLng object containing the coordinate for the center of the map var lat = document.getElementById('userLat').value; var lng = document.getElementById('userLng').value; var latlng = new google.maps.LatLng(lat, lng); // Creating an object literal containing the properties we want to pass to the map var options = { zoom: 15, // This number can be set to define the initial zoom level of the map center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP // This value can be set to define the map type ROADMAP/SATELLITE/HYBRID/TERRAIN }; // Calling the constructor, thereby initializing the map var map = new google.maps.Map(document.getElementById('map_div'), options); // Define Marker properties var imageuser = new google.maps.MarkerImage('img/pinfrend.png', // This marker is 129 pixels wide by 42 pixels tall. new google.maps.Size(38, 38), // The origin for this image is 0,0. new google.maps.Point(0,0), // The anchor for this image is the base of the flagpole at 18,42. new google.maps.Point(18, 38) ); var image = new google.maps.MarkerImage('img/pinuser.png', // This marker is 129 pixels wide by 42 pixels tall. new google.maps.Size(38, 38), // The origin for this image is 0,0. new google.maps.Point(0,0), // The anchor for this image is the base of the flagpole at 18,42. new google.maps.Point(18, 38) ); // Add Marker to display multi positions var frendlat = document.getElementById('frendLat').value; var frendlng = document.getElementById('frendLng').value; var marker2 = new google.maps.Marker({ position: new google.maps.LatLng(frendlat, frendlng), map: map, icon: imageuser // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin }); var marker1 = new google.maps.Marker({ position: new google.maps.LatLng(lat, lng), map: map, icon: image // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin }); // Add listener for a click on the pin google.maps.event.addListener(marker1, 'click', function() { infowindow1.open(map, marker1); }); // Add information window var infowindow1 = new google.maps.InfoWindow({ content: createInfo('Evoluted New Media', 'Ground Floor,&lt;br /&gt;35 Lambert Street,&lt;br /&gt;Sheffield,&lt;br /&gt;South Yorkshire,&lt;br /&gt;S3 7BH&lt;br /&gt;&lt;a href="http://www.evoluted.net" title="Click to view our website"&gt;Our Website&lt;/a&gt;') }); // Create information window function createInfo(title, content) { return '&lt;div class="infowindow"&gt;&lt;strong&gt;'+ title +'&lt;/strong&gt;&lt;br /&gt;'+content+'&lt;/div&gt;'; } }); </code></pre> <p>I have the below input values:</p> <pre><code>&lt;input id="userLat" type="text" name="val-lat" value="41.3275" /&gt; &lt;input id="userLat" type="text" name="val-lat" value="40.5486" /&gt; &lt;input id="userLat" type="text" name="val-lat" value="41.9637" /&gt; &lt;input id="userLng" type="text" name="val-lng" value="19.8189" /&gt; &lt;input id="userLng" type="text" name="val-lng" value="19.0056" /&gt; &lt;input id="userLng" type="text" name="val-lng" value="19.4513" /&gt; </code></pre> <p>Now i want to display a pin in a map for each userLat + userLng.</p> <p>How can i archive this result?</p> <p>I have tried with this script but i am getting only one pin not three pins as i have three values.</p>
 

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