Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

iPhone - GeoLocation

  • 23-06-2010 03:37PM
    #1
    Registered Users, Registered Users 2 Posts: 7,994 ✭✭✭


    Hi Folks,

    I'm looking for a good way to show a map with the users posiotion highlighted in iPhone. I have limited experience with Java which seems to be the way to call.

    The script I found at the moment is this:
    <script>
    function handler(location) {
    var message = document.getElementById("message");
    message.innerHTML ="<img src='http://maps.google.com/staticmap?center=&quot; + location.coords.latitude + "," + location.coords.longitude + "&size=300x200&maptype=map&zoom=16&key=GoogleAPIKey' />";
    message.innerHTML+="<p>Longitude: " + location.coords.longitude + "</p>";
    message.innerHTML+="<p>Latitude: " + location.coords.latitude + "</p>";
    message.innerHTML+="<p>Accuracy: " + location.coords.accuracy + "</p>";
    }
    navigator.geolocation.getCurrentPosition(handler);
    </script>

    It works really well. However, is there anyway to take the variables of Longitude and Latitude, and place them in a form field automatically? i.e. To upload your location?

    Thanks,

    ironclaw.


Comments

  • Closed Accounts Posts: 24 zoudards


    That's Javascript not Java ...

    Yes, you can add the location.coords.longitude (or any other var value) to any other HTML element. There you chose to incorporate them to the innerHTML of the element with the id "message". If you have a form element (like an input with type="text"), you can assign anything to its value property. That's the way to go if you want to assign anything to an element of a form.

    http://www.ryerson.ca/JavaScript/lectures/forms/textinput.html , that might help ;), it's quite a broad subject

    Check out w3schools and how the DOM works

    hth
    Zoudards


Advertisement