Commit c752a86b authored by Shashank Gurudu's avatar Shashank Gurudu
Browse files

full map view with zooming

parent c5684c63
window.onload = function() {
function getLocation() {
/* function getLocation() {
if (navigator.geolocation) {
console.log("hello");
navigator.geolocation.getCurrentPosition(showPosition);
......@@ -9,22 +9,37 @@ window.onload = function() {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
*/
function loadmap(){
if (navigator.geolocation) {
console.log("hello");
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var x= document.getElementById("out");
x.innerHTML = "Latitude: " + latitude + "<br>Longitude: " + longitude;
var img = new Image();
img.src = "http://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
x.appendChild(img);
new ol.Map({
layers: [
new ol.layer.Tile({source: new ol.source.OSM()})
],
view: new ol.View({
center: ol.proj.transform([longitude,latitude], 'EPSG:4326', 'EPSG:3857'),
zoom: 14
}),
target: 'demoMap'
});
}
document.getElementById("loca").addEventListener("click",function(){
getLocation();
loadmap();
//getLocation();
});
};
\ No newline at end of file
......@@ -6,12 +6,16 @@
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1">
<title>Hello World</title>
</head>
<body>
<!-- This code is in the public domain. Enjoy! -->
<button id="loca">Show my location</button>
<div id="out"></div>
</body
<div id="demoMap" style="height:250px"></div>
<script src="./ol/ol.js"></script>
</body>
</html>
......@@ -12,6 +12,7 @@
"permissions": {
"geolocation": {
"description" : "Used to locate me"
}
},
"systemXHR" : {}
}
}
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment