<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script src="js/jquery.geocomplete.js"></script>
function get_current_address(lat, lon) {
var geo = 'http://maps.google.com/maps/api/geocode/json?latlng=' + lat + ',' + lon + '&sensor=true';
$.getJSON(geo, function(data) {
for (var i = 0, l = data.results[0].address_components.length; i < l; i++) {
var item = data.results[0].address_components[i];
if (item.types[0] == "locality") {
$('#city').val(item.long_name);
} else if (item.types[0] == "route") {
$('#location').val(item.long_name);
}
}
});
}
function locSuccess(position) {
// initialize map with current position and calculate the route
get_current_address(position.coords.latitude, position.coords.longitude);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(locSuccess);
}
<input type="text" class="form-control input-height" name="city" size="30" id="city" placeholder="Vishakapatnam">
<input type="text" class="form-control input-height geocomplete" name="location" size="30" id="location" placeholder="Find Location">
<script src="js/jquery.geocomplete.js"></script>
function get_current_address(lat, lon) {
var geo = 'http://maps.google.com/maps/api/geocode/json?latlng=' + lat + ',' + lon + '&sensor=true';
$.getJSON(geo, function(data) {
for (var i = 0, l = data.results[0].address_components.length; i < l; i++) {
var item = data.results[0].address_components[i];
if (item.types[0] == "locality") {
$('#city').val(item.long_name);
} else if (item.types[0] == "route") {
$('#location').val(item.long_name);
}
}
});
}
function locSuccess(position) {
// initialize map with current position and calculate the route
get_current_address(position.coords.latitude, position.coords.longitude);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(locSuccess);
}
<input type="text" class="form-control input-height" name="city" size="30" id="city" placeholder="Vishakapatnam">
<input type="text" class="form-control input-height geocomplete" name="location" size="30" id="location" placeholder="Find Location">
0 comments:
Post a Comment