Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate geolocation demo to google maps api v3 #160

Merged
merged 1 commit into from
Jun 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/firefox/templates/firefox/geolocation.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ <h4 class="expander-header">How do I turn off Location-Aware Browsing permanentl

</div> <!-- end #main -->

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key={{ gmap_api_key }}"></script>
<script src="//maps.googleapis.com/maps/api/js?sensor=true&amp;key={{ gmap_api_key }}"></script>

{% endblock %}
57 changes: 22 additions & 35 deletions media/js/geolocation-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,39 @@ var overlay = null;

var geodemo = {
initialize: function() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.41, -122.08), 1);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
},

getCircleOverlay: function(lat, lon, err) {
// math lifted from maps.forum.nu. you want map examples, go there.
with (Math) {
var points = Array();
var d = err/6378800;// accuracy / meters of Earth radius = radians
var lat1 = (PI/180)* lat; // radians
var lng1 = (PI/180)* lon; // radians

for (var a = 0 ; a < 361 ; a+=10 ) {
var tc = (PI/180)*a;
var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
points.push(point);
}
}
return new GPolygon(points,'#0000ff',1,1,'#0000ff',0.2)
},

zoomLevel: function(a, step) {
step++;
map.setCenter(new GLatLng(a.coords.latitude, a.coords.longitude), step);
if (step > 14) return;
window.setTimeout(function() { geodemo.zoomLevel(a, step) }, 250);
map = new google.maps.Map(document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.41, -122.08),
zoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
},

aaa: function(a) {
var center = new google.maps.LatLng(a.coords.latitude, a.coords.longitude);
$('#locateButton').siblings('img').hide();
var zoomLevel = 14;

if (a.coords.accuracy > 500)
zoomLevel = 10;

map.setCenter(new GLatLng(a.coords.latitude, a.coords.longitude), zoomLevel);
map.setCenter(center);
map.setZoom(zoomLevel);

if (overlay) map.removerOverlay(overlay);
if (overlay) {
overlay.setMap(null);
overlay = null;
}

overlay = geodemo.getCircleOverlay(a.coords.latitude, a.coords.longitude, a.coords.accuracy);
map.addOverlay(overlay);
overlay = new google.maps.Circle({
center: center,
radius: a.coords.accuracy,
fillColor: '#0000ff',
fillOpacity: 0.2,
strokeColor: '#0000ff',
strokeOpacity: 1,
strokeWeight: 1
});
overlay.setMap(map);
},

handleError: function(a) {
Expand Down