-
Notifications
You must be signed in to change notification settings - Fork 0
/
prueba.html
152 lines (134 loc) · 4.64 KB
/
prueba.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
<title>Map</title>
<link rel="stylesheet" href="css/jquery.mobile-1.0.1.css" />
<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.0.1.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/cordova-1.5.0.js"></script>
<script type="text/javascript">
var map;
var marker;
var infowindow;
var watchID;
$(document).ready(function(){
document.addEventListener("deviceready", onDeviceReady, false);
//for testing in Chrome browser uncomment
//onDeviceReady();
});
//PhoneGap is ready function
function onDeviceReady() {
$(window).unbind();
$(window).bind('pageshow resize orientationchange', function(e){
max_height();
});
max_height();
google.load("maps", "3.8", {"callback": map, other_params: "sensor=true&language=en"});
}
function max_height(){
var h = $('div[data-role="header"]').outerHeight(true);
var f = $('div[data-role="footer"]').outerHeight(true);
var w = $(window).height();
var c = $('div[data-role="content"]');
var c_h = c.height();
var c_oh = c.outerHeight(true);
var c_new = w - h - f - c_oh + c_h;
var total = h + f + c_oh;
if(c_h<c.get(0).scrollHeight){
c.height(c.get(0).scrollHeight);
}else{
c.height(c_new);
}
}
function map(){
var latlng = new google.maps.LatLng(55.17, 23.76);
var myOptions = {
zoom: 6,
center: latlng,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
//get geoposition once
//navigator.geolocation.getCurrentPosition(geo_success, geo_error, { maximumAge: 5000, timeout: 5000, enableHighAccuracy: true });
//watch for geoposition change
watchID = navigator.geolocation.watchPosition(geo_success, geo_error, { maximumAge: 5000, timeout: 5000, enableHighAccuracy: true });
});
}
function geo_error(error){
//comment
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
function geo_success(position) {
map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
map.setZoom(15);
var info =
('Latitude: ' + position.coords.latitude + '<br>' +
'Longitude: ' + position.coords.longitude + '<br>' +
'Altitude: ' + position.coords.altitude + '<br>' +
'Accuracy: ' + position.coords.accuracy + '<br>' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br>' +
'Heading: ' + position.coords.heading + '<br>' +
'Speed: ' + position.coords.speed + '<br>' +
'Timestamp: ' + new Date(position.timestamp));
var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
if(!marker){
//create marker
marker = new google.maps.Marker({
position: point,
map: map
});
}else{
//move marker to new position
marker.setPosition(point);
}
if(!infowindow){
infowindow = new google.maps.InfoWindow({
content: info
});
}else{
infowindow.setContent(info);
}
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
</script>
</head>
<body>
<div data-role="page" id="index">
<div data-role="header" data-theme="b"><h1>Map Header</h1></div>
<div data-role="content" style="padding:0;">
<div id="map" style="width:100%;height:100%;"></div>
</div>
<div data-role="footer" data-theme="b"><h4>Map Footer</h4></div>
</div>
</html>
<script>
$("#btn").bind ("click", function (event)
{
var lat = $("#lat").val ();
var lng = $("#lng").val ();
var latlng = new google.maps.LatLng (lat, lng);
var options = {
zoom : 15,
center : latlng,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var $content = $("#win2 div:jqmData(role=content)");
$content.height (screen.height - 50);
var map = new google.maps.Map ($content[0], options);
$.mobile.changePage ($("#win2"));
new google.maps.Marker (
{
map : map,
animation : google.maps.Animation.DROP,
position : latlng
});
});
</script>