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
    • 641
    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:

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <!-- here add goole map css -->
    5. <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    6. <!-- here add goole map libraries -->
    7. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
    8. <script>
    9. var autocomplete;
    10. //start initialize() function
    11. function initialize() {
    12. autocomplete = new google.maps.places.Autocomplete(
    13. /** @type {HTMLInputElement} */(document.getElementById('autocomplete')),
    14. { types: ['geocode'] });
    15. google.maps.event.addListener(autocomplete, 'place_changed', function() {
    16. });
    17. }
    18. </script>
    19. </head>
    20.  
    21. <body onload="initialize()">
    22. <div id="locationField">
    23. <input id="autocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text"></input>
    24. </div>
    25. </body>
    26. </html>
    27.  

     

    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
Reset Password
Fill out the form below and reset your password: