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)