2017年8月14日 星期一

Using geolocation

Ref : https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation


Ref : https://developer.mozilla.org/en-US/Apps/Fundamentals/gather_and_modify_data/Plotting_yourself_on_the_map






<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>

function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';

    var img = new Image();
    img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";

    output.appendChild(img);
  }

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  }

  output.innerHTML = "<p>Locating…</p>";

  navigator.geolocation.getCurrentPosition(success, error);
}





1 則留言:

  1. Casino - Dr.MCD
    Casino. 광명 출장안마 Dr.MCD has been providing 익산 출장마사지 players with a place 제천 출장마사지 for 대구광역 출장샵 quality casino 파주 출장안마 entertainment and gaming excellence for over 20 years. For our continuous commitment to Nov 30, 2021 · Uploaded by Dr.MCD

    回覆刪除