Javascript - Save Geolocation Coordinates

I would like to save the coordinates in localstorage so that it shouldn't ask the users every time to allow GPS or Location and a button to clear the localstorage value so it can again ask for coordinates?

Also it should work with Android & IOS Mobile View.

FYI: I am using Praytimes JS to display Muslim prayer times but for each location i have to manually add latitude & longitude of that location.

Below is my code:

<script type="text/javascript" src="[login to view URL]"></script>

<script type="text/javascript">

var x = [login to view URL]("currentlocation");

var geocoder;

if ([login to view URL]) {

[login to view URL](successFunction, errorFunction);


//Get the latitude and the longitude;

function successFunction(position) {

var lat = [login to view URL];

var lng = [login to view URL];

codeLatLng(lat, lng)


function errorFunction(){

$('#currentlocation').html("Geocoder failed");


function initialize() {

geocoder = new [login to view URL]();


function codeLatLng(lat, lng) {

var latlng = new [login to view URL](lat, lng);

[login to view URL]({'latLng': latlng}, function(results, status) {

if (status == [login to view URL]) {

[login to view URL](results)

if (results[1]) {

//formatted address


//find country name

for (var i=0; i<results[0].[login to view URL]; i++) {

for (var b=0;b<results[0].address_components[i].[login to view URL];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_2") {

//this is the object you are looking for

city= results[0].address_components[i];





//city data

$('#currentlocation').html(city.short_name + " " + city.long_name)

} else {

$('#currentlocation').html("No results found");


} else {

$('#currentlocation').html("Geocoder failed due to: " + status);





<p id="currentlocation"></p>

<script type="text/javascript" src="[login to view URL]"></script>

<script type="text/javascript">

function loadTable(position) {

[login to view URL]('MWL');

var date = new Date(); // today

var times = [login to view URL](date, [[login to view URL], [login to view URL]]);

var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

var html = '<table id="timetable">';

html += '<tr><th colspan="2">'+ [login to view URL]()+ '</th></tr>';

for(var i in list) {

html += '<tr><td>'+ list[i]+ '</td>';

html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';


html += '</table>';

[login to view URL]('table').innerHTML = html;


if ([login to view URL]) {

[login to view URL](loadTable);



Skills: Android, HTML5, iPhone, Javascript, jQuery / Prototype

See more: navigator geolocation, w3c geolocation api, how much to add on printing cost as graphic designer, how do you add money to paypal, how i can save energy creative writing, google maps javascript api geolocation, silverlight save controls coordinates, javascript auto click coordinates, javascript yahoo maps coordinates marker, add runtime input html tag display extjs, php using xml file save database, allow frontend users add products virtuemart, friends myspace add 5000 times day, allow registered users add entry sobi2, javascript calculator clear button

About the Employer:
( 4 reviews ) salmiya, Kuwait

Project ID: #17329237

Awarded to:


I am a Software Engineer having 6 years of extensive hands-on experience in Object Oriented Analysis & Design (OOAD) and Database Design and Implementation using Agile, UML, .NET Framework, C#, ASP.NET, ASP.NET MVC, T More

$10 USD in 0 days
(4 Reviews)

7 freelancers are bidding on average $31 for this job

$55 USD in 1 day
(223 Reviews)

Dear Hiring Manager, We are very passionate developers with 5+ years of experience in iPhone/iPad, Android application development. Our skills in specially Ios, Android, Objective C, C, C++, MySql, Git, Swift, A More

$25 USD in 1 day
(13 Reviews)
$25 USD in 1 day
(42 Reviews)

Hello, I have 6+ years experience in PHP, WordPress & Codeigniter. I Read your job description, I'm interesting in your job. we feel that we are suitable for the job. As a senior WordPress expert, I'll be glad More

$55 USD in 1 day
(9 Reviews)
$25 USD in 1 day
(3 Reviews)
$25 USD in 1 day
(2 Reviews)