-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.php
61 lines (51 loc) · 1.95 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Reverse Geocoding</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=AIzaSyAABejZuAsySdz5ubatZYvla_uHY1aJ7YY&ver=3.exp"></script>
<script type="text/javascript">
jQuery( document ).ready( function($) {
$( "#get-mylocation" ).click( function(e) {
e.preventDefault();
/* Chrome need SSL! */
var is_chrome = /chrom(e|ium)/.test( navigator.userAgent.toLowerCase() );
var is_ssl = 'https:' == document.location.protocol;
if( is_chrome && ! is_ssl ){
return false;
}
/* HTML5 Geolocation */
navigator.geolocation.getCurrentPosition(
function( position ){ // success cb
/* Current Coordinate */
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var google_map_pos = new google.maps.LatLng( lat, lng );
/* Use Geocoder to get address */
var google_maps_geocoder = new google.maps.Geocoder();
google_maps_geocoder.geocode(
{ 'latLng': google_map_pos },
function( results, status ) {
if ( status == google.maps.GeocoderStatus.OK && results[0] ) {
console.log( results[0].formatted_address );
}
}
);
},
function(){ // fail cb
}
);
});
});
</script>
</head>
<body >
<a id="get-mylocation" href="#">aaa</a>
<form method="post" action="" name="local_cityname">
<div id="local_state"></div>
<div id="local_city"></div>
</form>
</body>
</html>