0

I am trying to load my current location in webview.

But navigator.geolocation is returning undefined? also same with navigator.online?

is navigator object not supported in webview of android?

How do i get my current device location?

user3231742
  • 77
  • 1
  • 2
  • 10

1 Answers1

0

i am using window.navigator.onLine which is giving me true when i connect to internet else it gives false;

and dont forget to add to config.xml

 <feature name="NetworkStatus" >
        <param
            name="android-package"
            value="org.apache.cordova.NetworkManager" />
    </feature>

AndroidManifest.xml

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

to get currentlocation:

<script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
<script type="text/javascript" charset="utf-8">
    document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){

        navigator.geolocation.getCurrentPosition(onSuccess, onError, {
            maximumAge : 3000,
            timeout : 5000,
            enableHighAccuracy : true
        });
 }
    var address;
    function onSuccess(position) {
        var reverseGeocoder = new google.maps.Geocoder();
        var currentPosition = new google.maps.LatLng(position.coords.latitude,
                position.coords.longitude);
        reverseGeocoder.geocode({
            'latLng' : currentPosition
        }, function(results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                address= results[0].formatted_address;


                }else{
                addess='address not found';
                }

            }
        });

    }

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        //alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
  }

console.log(address);
</script>

add config.xml

<feature name="Geolocation" >
        <param
            name="android-package"
            value="org.apache.cordova.GeoBroker" />
    </feature>

add androidmanifest.xml

raj
  • 2,088
  • 14
  • 23
  • Hi Raj, Thanks for sharing your knowledge. But where to put this config.xml? i am not using any build tools like Phonegap. – user3231742 Nov 13 '14 at 11:35