Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get city name with geolocation API from a input form ?.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 606
    Comment on it

    Hi Reader's,
      Welcome to FindNerd, today we are going to discuss how to get city name from google maps from a PHP input form.

    If you are trying to get city name displaying location information based on the IP address geolocation from a input form then you can use Geolocation API to locate a user's position.
      So you can use  geolocate() function for getting location information in a input form when you will type a first character of city name.

    In a web applications the geolocation API allows the user to provide their location.

    you have to use below code:

    <!DOCTYPE html>
        <html>
          <head>
             <!-- here add goole map css -->
            <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
            <!-- here add goole map libraries -->
            <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
            <script>
                var autocomplete;
                //start initialize() function
                function initialize() {
                  autocomplete = new google.maps.places.Autocomplete(
                      /** @type {HTMLInputElement} */(document.getElementById('autocomplete')),
                      { types: ['geocode'] });
                  google.maps.event.addListener(autocomplete, 'place_changed', function() {
                  });
                }
            </script>
          </head>
    
          <body onload="initialize()">
            <div id="locationField">
              <input id="autocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text"></input>
            </div>
          </body>
        </html>
    

     

    Suppose if you are in London and you will fill in input box L then London will automatically come in input box just you have to select it.

     Note: For privacy reasons, the user is asked for permission to report location information.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: