If you have projects web application and need to get geo location from user location. You can using javascript for this feature, but.. if get geo location using from browser may be not 100% accuracy, so you can try it.

In your HTML code, describe how get or put data into the markup element id or class.
<form id="contact" action="" method="post" align="center">
  <input placeholder="Your Address" id="address" type="text" tabindex="1" required autofocus>
  <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 

The you can write with this code.
$(document).ready(function ()
var currgeocoder;
//Set geo location lat and long
navigator.geolocation.getCurrentPosition(function (position, html5Error) {
    geo_loc = processGeolocationResult(position);
    currLatLong = geo_loc.split(",");
    initializeCurrent(currLatLong[0], currLatLong[1]);
//Get geo location result
function processGeolocationResult(position) {
    html5Lat = position.coords.latitude; //Get latitude
    html5Lon = position.coords.longitude; //Get longitude
    html5TimeStamp = position.timestamp; //Get timestamp
    html5Accuracy = position.coords.accuracy; //Get accuracy in meters
    return (html5Lat).toFixed(8) + ", " + (html5Lon).toFixed(8);
//Check value is present or
function initializeCurrent(latcurr, longcurr) {
    currgeocoder = new google.maps.Geocoder();
    console.log(latcurr + "-- ######## --" + longcurr);
    if (latcurr != '' && longcurr != '') {
        //call google api function
        var myLatlng = new google.maps.LatLng(latcurr, longcurr);
        return getCurrentAddress(myLatlng);
//Get current address
function getCurrentAddress(location) {
        'location': location
    }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
        } else {
            alert('Geocode was not successful for the following reason: ' + status);

Or you can using this code for get latitude and longitude on change from element

<script language="javascript">
var x = document.getElementById("#geo"); function getLocation() {
    if (navigator.geolocation) {
    } else {
        x.innerHTML = "Geolocation is not supported by this browser. Please enable permision from your devices browser";
function showPosition(position) { document.getElementById('latitude').value=position.coords.latitude;

If button Submit on click, addresses from geo location automaticaly put on text, addresed get from Google Maps API

This code has get from jsfiddle.net and for solution on stackoverflow.com (Just posting for my notes only)

FYI: now all applications using maps API required with key identified Google Console.

Post a Comment

Silahkan anda tulis komentar di bawah ini !