get lat and long from city name using jquery

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body>
   <?php $city='indore'; ?>
    <input id="btn" type="button" value="search for miami coordinates" />
    <input type="hidden" class="cityName" name="cityName" value="<?php echo $city; ?>" />
    <script>
jQuery(document).ready(function($){
var cityName=$('.cityName').val();
            var geocoder =  new google.maps.Geocoder();
    geocoder.geocode( { 'address': cityName}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            alert("location : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng());
          } else {
            alert("Something got wrong " + status);
          }
        });
});
</script>
   
</body>
</html>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

membership registration and login system in php