-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (91 loc) · 3.51 KB
/
index.html
File metadata and controls
95 lines (91 loc) · 3.51 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable:no;">
<title>Map-based Country Chooser Demo</title>
<style type="text/css">
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
#map_canvas {
width: 300px;
height: 200px;
margin-left: 20px;
}
#chosencountry{
margin: 20px;
width: 300px;
}
</style>
<body>
<input type="text" id="chosencountry" value="Choose your country...">
<div id="map_canvas"></div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script>
var map, geocoder;
function initialize() { //This is the name of the callback parameter passed to the googlemaps script
var myOptions = {
zoom: 0,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
zoomControlOptions: {position: google.maps.ControlPosition.RIGHT_BOTTOM},
panControl: false,
streetViewControl: false,
mapTypeControl: false
};
map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
geocoder = new google.maps.Geocoder();
google.maps.event.addListener(map, 'click', function(e) {
var clickPos = new google.maps.LatLng(e.latLng["$a"],e.latLng['ab']);
codeLatLng(clickPos);
});
}
function codeLatLng(position) {
geocoder.geocode({'latLng': position}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
for(var k=results.length - 1; k >= 0; k++){
result = results[k];
var components = result.address_components;
for(var i=components.length-1; i >= 0 ; i--){
var componentTypes = components[i].types;
for(var j=0; j<componentTypes.length; j++){
if(componentTypes[j]=="country"){
$("#chosencountry").val(components[i].long_name).focus();
hideMap();
return;
}
}
}
}
}
//Could not find out what country this was in. Let's zoom in where the user clicked.
map.setCenter(position);
map.setZoom(map.getZoom()+1);
});
}
function showMap(){
$("#map_canvas").css("left","");
}
function hideMap(){
$("#map_canvas").css("left","-9999px");
}
$(document).ready(function(){
hideMap();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.googleapis.com/maps/api/js?key=AIzaSyBIZN5Mnn6knQAcU3dYsl0ict1_uY-kTwA&sensor=false&' +'callback=initialize';
document.body.appendChild(script);
$("#chosencountry").click(function(){
showMap();
this.blur();
})
.focus(function(){
this.click();
this.blur();
});
});
</script>