Geolocation native

98 views
Skip to first unread message

Selo Soft

unread,
May 17, 2015, 5:09:39 AM5/17/15
to androi...@googlegroups.com
Hi ..

Does not work html code in Droidscript .
work in firefox and chrome .





<html>
 <head>
  <script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></
script>
 </head>
 <body>
  <script language="Javascript">
        document.write("Welcome to our visitors from "+geoplugin_city()+", "+geoplugin_countryName());
  </script>
 </body>
</html><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Reverse Geocoding</title>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  var geocoder;

  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
//Get the latitude and the longitude;
function successFunction(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    codeLatLng(lat, lng)
}

function errorFunction(){
    alert("Geocoder failed");
}

  function initialize() {
    geocoder = new google.maps.Geocoder();



  }

  function codeLatLng(lat, lng) {

    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
      console.log(results)
        if (results[1]) {
         //formatted address
         alert(results[0].formatted_address)
        //find country name
             for (var i=0; i<results[0].address_components.length; i++) {
            for (var b=0;b<results[0].address_components[i].types.length;b++) {

            //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
                    //this is the object you are looking for
                    city= results[0].address_components[i];
                    break;
                }
            }
        }
        //city data
        alert(city.short_name + " " + city.long_name)


        } else {
          alert("No results found");
        }
      } else {
        alert("Geocoder failed due to: " + status);
      }
    });
  }
</script>
</head>
<body onload="initialize()">
<body onload=" city.short_name ()">
</body>
</html>

Dave Smart

unread,
May 17, 2015, 5:35:46 AM5/17/15
to androi...@googlegroups.com
Hi,

You will probably find that it works on Android Lollipop if you have the latest webview component installed

Here is a link to  what is supported :-  https://developer.chrome.com/multidevice/webview/overview

P.S. I think someone on this forum has created a wrapper that allows the native DroidScript geolocation to be used from an HTML page.

Steve Garman

unread,
May 17, 2015, 5:48:30 AM5/17/15
to androi...@googlegroups.com
Yes, it's here https://groups.google.com/forum/m/#!topic/androidscript/Xf-RAmITvRg
but I think Selo Soft has already seen it.

Selo Soft

unread,
May 18, 2015, 3:42:46 AM5/18/15
to androi...@googlegroups.com
Hi Steve ..

I did not get the answer to the question I asked again .
Thanks
Reply all
Reply to author
Forward
0 new messages