Trouble getting location from a html page

Hi there,

I’m not too sure if this would work even but I have created a html page that gives the user their Lat and Long, and I wanted to be able to access that from my app.

I grabbed this example and it works great in a browser but I cant seem to grab that response from within the app -

<!DOCTYPE html>
<html>
<body>
<body onload="getLocation()">
<script>
var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "
Longitude: " + position.coords.longitude;   
}
</script>
</body>
</html>

Any ideas how I could do that???

Thanks,
Pete

Hello,

i think u can use the WWW class to get the text of your web page (mywww.text)

Hey thanks,

I tried that but it seems to return the html contents rather than the response.
So I was trying something like this -

    var url = "http://blah/Locate.html";
    var www : WWW = new WWW (url);
    yield www;
    if (www.error != null){
        print ("Error getting your location "+www);
        return;
    }else{
        print (www.text);
    }

And this is what I get back -

<!DOCTYPE html>
<html>
<body>
<body onload="getLocation()">

etc..

Why don’t use the LocationService in unity or request your location from an online location service api?

Yeah, I wanted to have a fallback for GPS location.
I originally have an online geolocation api but they closed and my app kinda broke :slight_smile:
I think I’ll go down that path again though because it worked pretty well while it lasted.

Hello,

i thought that was possible but javascript code is not executed, so you get html text only, my bad.
That seems to be possible using System.Net.HttpWebRequest, well i read that’s not works with webplayer. so anyway Mich solution sounds better :slight_smile:

Ahh yeah that sounds right.
Yeah I think I’ll stick with the web API for now.

Thanks