0

I have this javascript script, and I would like to print latitude and longitude obtained through geolocation in the same html page where the script is added. How can I do that?

Edit : I specified my question

3

3 Answers 3

2

I think you are asking how to display latitude and longitude that you already have, rather than actually obtaining latitude and longitude. If this is the case, you can do this:

<dl>
   <dt>Latitude</dt>
   <dd id="latitude"></dd>
   <dt>Longitude</dt>
   <dd id="longitude"></dd>
</dl>
<script type="text/javascript">
    document.getElementById("latitude").innerHTML = "lat value";
    document.getElementById("longitude").innerHTML = "long value";
</script>

If this is not the case, you question should probably be "How do I obtain the current latitude and longitude of the website visitor?".

Sign up to request clarification or add additional context in comments.

4 Comments

I don't think so. He used the word "retrieve" in the original post.
I was confused by "I have this javascript script" - sounds like the OP doesn't have a script, but wants one maybe?
@ShaiMishali Ok I specified my question...what Sohnee says is what I need...Since I'm italian I made mistake using words
Gotya, so my answer below is irrelevant :) I'll leave it anyways for reference.
1

Here is the jsfiddle that will do what you need.

Comments

-1


I don't think its possible to get the location on a regular computer since most of those don't have a GPS.

If you are speaking about getting the location using Javascript on a mobile device, that makes a bit more sense . There are several libraries available such as geo-location-javascript on google-code. Also this article isn't bad : http://www.greenhughes.com/content/where-are-you-find-out-geolocation-javascript

Usually when services get your estimated location in a browser, without having a GPS on the device, they do it by analyzing your IP address infront of a database that has the locations of all IP addresses in the world. But again, that is only an estimate and usually not "accurate" as an actual GPS. MaxMind are probably the largest company offering this service.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.