1

First, sorry for my english. I'm developing an Android App using phonegap. I'm using html with css, js, and json hosted to the server.

I have a .json data that contains latitude and altitude data. The .json data displayed on html as lists. And then i want when i open the html, it will detect my current location using geolocation and then automatically measure distance between my current location and all of my .json data in kilometres

Which one i have to use and how to do that. Determine my position from GPS (phonegap) or with html geolocation? and then show the distance from my current position with my json data (altitude and longitude)

Here is the example

This my json data (i'm using json2html transform)

// Geo - i got that numbers from google maps
    var content = [{
    "geo-00":"geo:40.948823, -74.066191?q=40.948823, -74.066191?z=17",
    "geo-01":"geo:40.930027, -74.105579?q=40.930027, -74.105579?z=17",
    "geo-02":"geo:40.966902, -74.078574?q=40.966902, -74.078574?z=17",
}];

// List
var rules = [
    {"tag":"a","href":"${geo-00}","class":"loc-link"},
    {"tag":"a","href":"${geo-01}","class":"loc-link"},
    {"tag":"a","href":"${geo-02}","class":"loc-link"},
];

// JS Write
var page = json2html.transform(content,rules);document.write(''+page+'');
user3408707
  • 29
  • 1
  • 5
  • _"it will force to detect my current location (without asking)"_ That's not possible. The user will _always_ have to allow the webpage to access location information. – Cerbrus Nov 10 '15 at 07:34
  • 1
    You are going to want to use the Haversine formula https://en.wikipedia.org/wiki/Haversine_formula – zipzit Nov 10 '15 at 07:37
  • Okay, i'll edit the question, thanks before – user3408707 Nov 10 '15 at 07:40
  • For the first question, getting geodata on html load, what unit are you using and how? Mobile? As for the second it is purely maths :) A typical way: Get distances between long and lat for the two points you are comparing, as in a point from your list, and the point you read from the unit A good accepted answer describing it can be seen here: http://stackoverflow.com/questions/365826/calculate-distance-between-2-gps-coordinates – Richard Tyregrim Nov 10 '15 at 07:41
  • i would like using kilometers, it's like Chat apps or google map that displaying how far our position to some places. Office 5.1 km School 2.1 km – user3408707 Nov 10 '15 at 08:53

0 Answers0