Ways to get location of the client from the browser?

前端 未结 6 1631
情深已故
情深已故 2021-01-06 04:40

What i need is the lat/long of the client(via browser)

Found some articles on the net,found some in stack overflow itself(an old article) Get GPS location from the w

6条回答
  •  走了就别回头了
    2021-01-06 04:57

    Try HTML5 geolocation

     function init() {
    
    
     var mapOptions = {
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
     };
    
    
     map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
    
    
    
    if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude);
    
      var infowindow = new google.maps.InfoWindow({
        map: map,
        position: pos,
        content: 'Location found using HTML5.'
      });
    
      map.setCenter(pos);
    }
    
     } else {
    alert('Geolocation not detected');   
    }
    }
    

提交回复
热议问题