0

I am using Ubuntu 14.04. I am facing an issue with google maps geo-location. I wrote a piece of code which shows geo-location map in my project, initially it worked fine. But I am facing an issue with this now. Even the link https://developers.google.com/maps/documentation/javascript/examples/map-geolocation is always throwing an error. In windows it works fine but not in Ubuntu. I tried in various computers running on Ubuntu, I got same error. Can anyone help me?

Thanks in advance.

Here is my script code:

if(navigator.geolocation)
{
  navigator.geolocation.getCurrentPosition(success, displayError, options);
}
var options = {
                enableHighAccuracy: true,
                timeout: 30000,
                maximumAge: 0
              };
// SUCCESS(POSITION) FUCNTION FOR SHOWING CURRENT LOCATION OF THE USER
function success(position) {
  if(navigator.geolocation){
      var myLatLng={lat:position.coords.latitude , lng:position.coords.longitude}
      var map = new google.maps.Map(document.getElementById('googleMap'),
      {
       center:myLatLng ,
       zoom: 8
      });
      var marker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      });
  }
}
// IN THIS FUNCTION WE HAVE SET STANDARD LAT LNG FOR STANDARD MAP(IF GPS NOT AVAIALABLE)
function displayError(err) {
  map = new google.maps.Map(document.getElementById('googleMap'), {
          center: {lat: 28.644800, lng: 77.216721},
          zoom: 8
        });
};

Here is my html code:

<script src="
    https://maps.googleapis.com/maps/api/js?key=mykey"></script>
<div id="googleMap"></div>

Screenshot

1 Answers1

0

So, if you try get the current position in chrome, you need use security origins or https environment.

For more details: https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only.

I hope help you!

thulioph
  • 46
  • 3
  • I used security origins only. Even the link https://developers.google.com/maps/documentation/javascript/examples/map-geolocation is passed in to the failure callback of the Geolocation APIs. – sowjanya sowji Aug 06 '16 at 07:23
  • sorry, my last comment it was wrong, consider bellow: See there two links: [http://d.pr/i/qqwf/4Cy2tLC8](http://d.pr/i/qqwf/4Cy2tLC8) is one screenshot of my test, [http://d.pr/i/1gERw/3XI54lVx](http://d.pr/i/1gERw/3XI54lVx) if you use the chrome as a browser, search for target icon (and click to open the box) in the address bar. – thulioph Aug 16 '16 at 02:17