Google API: How to pass zip-code value into the JavaScript code -


i using html form input zip-codes (portzip)

port zipcode:<br> <input type="text" id="portzip" value="31402"> 

and want pass zip-code value java script code line

var point1 = new google.maps.latlng(-33.8975098545041,151.09962701797485); 

currently java script code line takes latlng values manually. how change java script code line take zip-code value?

use geocoder translate addresses (or zipcodes) geographic coordinates can used in google maps javascript api.

code snippet:

var geocoder;  var map;    function initialize() {    geocoder = new google.maps.geocoder();    map = new google.maps.map(      document.getelementbyid("map_canvas"), {        center: new google.maps.latlng(37.4419, -122.1419),        zoom: 13,        maptypeid: google.maps.maptypeid.roadmap      });    codeaddress(document.getelementbyid('portzip').value);  }  google.maps.event.adddomlistener(window, "load", initialize);    function codeaddress(address) {    geocoder.geocode({      'address': address    }, function(results, status) {      if (status == google.maps.geocoderstatus.ok) {        map.setcenter(results[0].geometry.location);        var marker = new google.maps.marker({          map: map,          position: results[0].geometry.location        });      } else {        alert("geocode not successful following reason: " + status);      }    });  }
html,  body,  #map_canvas {    height: 500px;    width: 500px;    margin: 0px;    padding: 0px  }
<script src="https://maps.googleapis.com/maps/api/js"></script>  port zipcode:  <br>  <input type="text" id="portzip" value="31402">  <div id="map_canvas" style="width:750px; height:450px; border: 2px solid #3872ac;"></div>


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -