HTML5 Geolocation: measures when not moving - html

I have a web app that allows users to create a cardio workout where they may or may not be actually moving. They could create a "run" either outside or on a treadmill. Either way, geolocation is automatically enabled for the workout.
But I only show the distance on the screen if they have moved at least .25 of a mile. I have tested this myself and the problem is that geolocation is telling me I'm moving even when I'm not!
This evening I was on the eliptical machine for 32 minutes and my app told me I had moved 1.15 miles.
If I test the app when actually moving, (e.g. in a car, on a bike, etc.) geolocation works fine. It's only when I'm NOT moving that I'm having problems.
Anyone else face this issue? Is there perhaps a hack to prevent it?
I'm using Chrome for Android as the browser.

Well I've come up with my own solution to this issue. I'm sure it's not perfect, but it seems to be working well. It is partially based on this excellent article...
Getting the best single location
For my web app, I used an array to capture 50 lat/lng's with an accuracy of less than 11 meters. After capturing the 50th coordinate, I grab the next lat/lng to be my current position. I am basically assuming that after checking 50 coordinates with accuracies better than 11 meters, I should have a pretty good idea where I am.
When checking coordinates on indoor WiFi (such as in a gym on a treadmill) the accuracies rarely get near 11 meters, and the array either does not fill up, or it takes a half hour or so to fill. Even so, by that point my position is pretty stable, and the app will not calculate distance when I'm not actually moving.
When outside using cell towers, the array will fill with 50 coordinates normally in less than 30 seconds. This means that I lose the first 30 seconds of the persons movement. But if you're walking or riding a bike, that really isn't missing much. In the end, my distance measurement may be off by .15 of a mile or such. I can live with that.
The biggest lesson I've learned is that "getCurrentPostion()" for HTML5 geolocation is basically worthless. The method simply forces lat/lng coordinates out of the phone, which are usually way off. In my code I call "updateLocation()" 50 times to collect the coordinates. In the end, this is much more accurate.
Take some time and read the article posed above. You'll learn a lot.

Related

Even if I don't move, my flutter location/geolocator's current location keep changing?

I am using Flutter to write my running app likes Strava. In this app, I used location and google maps plugin for flutter. Everything is good until I call getCurrentLocation every 10s to track my location and receive different LatLng even if I stand still.
Did anybody here face the same problem? I think it probably cause by the GPS's accuraccy issue.
Every few seconds, Android (and ios) gets a new location by either connect to cell towers or connecting to gps satellites. Based on that data it determines the most likely location for you on the globe. Since these measurements are not 100% accurate, every time it recalculates the users location, there will be a slight difference in location. Even if you stand still, your lat-lng values will change slightly. That is normal. You can decide to discard the new value if it is too close to the previous one. maps_toolkit is a good library for calculating the distance between two locations.

Google Direction Service: Estimating U turn at slightest deviation from route

I am using Google Direction Service for route drawing by providing it way points (recorded at some specific time interval). While drawing, it, sometimes (may be due to slight error in GPS measurement), it draws like the vehicle took a U turn to reach there. I guess it can be solved only if google ignores road dividers.
For example:
Look at the below picture, my vehicle moves on left road, but due to GPS accuracy issues, it sometimes gives me coordinates on right part of road. And when I give the coordinates to google to draw the the path, it gives me a U - Turn.
Can anybody please tell me how can I solve this issue?

Given a list of GPS positions, how do I display route using Google Maps API

I have lists of between 100 and 10000 GPS location from vehicles driving around during some timespan.
I want to display that on a Google Map, using their API (with the Business licence if that matters).
As I see it, there are 3 options, all with problems:
1) Draw a polyline between all positions. Some positions are not that accurate so it looks like the route hits some buildings next to the road. I know that all positions are on a road. Also, it cuts some corners, and it doesn't look professional.
2) Display just the GPS positions in the map. This is not good either since the GPS positions are off the road (which they shouldn't be).
3) Draw the route using Maps API. This limits us to using 23 waypoints between the start and end positions. The route looks excellent and it follows the road (GPS positions next to the road are moved to the road automatically). But especially for longer time spans, this option means that the route displayed is incorrect (Google guesses the route taken between the waypoints - so from the 10000 GPS positions it only uses 23). And we can't display a clearly incorrect route.
Does anyone have a good/better way to show a driven route on Google Maps that follows the road but takes into account all/many given GPS positions?
Could you not chain the route using the maps API? It's not something I've done before so this answer could be a little vague but would it not be possible to segment your list of coordinates into chunks of 23 fire the requests and then display the resultant routes on the map?
I'm not overly sure on the return format so it may be necessary to mess with the output in order to give the illusion of the route, also you will likely not need to use every coordinate (perhaps exclude those that are within a small distance of each other for example being stuck at lights), otherwise the requests may take a long time.
We've actually moving away from option 3. The reason is that when the positions get moved to the nearest road, that is not always correct (like if you're driving on a parking lot), so since that doesn't always give the correct route, then we'll not take that path.
So I don't know if it's possible to chain several routes in the same map.

Same address Google Maps - any ideas how to facilitate?

So I am trying to think of a way to facilitate two things. It may end up being a two step process in the end but I was looking for input.
The first thing I need to do is accommodate locations with the same address. The two scenarios that come to mind are businesses that share a location and apartment buildings.
The second thing I need to accommodate is a business/nonprofit with no headquarters, just a town. Right now I just map them to the town center, but if multiple businesses have no headquarters I run into the first problem.
So I did some Googling and found a solution that involved having a list of locations alongside the map so you can click on them and the info window will pop up. This isn't a solution for me though.
What I was thinking of was using the location to map the first point. For the second and points after that moving the marker over .05 degrees or something marginal so that the marker shows up. The inherent problem with that is that what happens if 12 Main Street turns into 13 Main Street?
So any thoughts on what I could do?
Thanks
Levi
There's an extension by Martin Pearman called ClusterMarker that detects any groups of two or more markers whose icons visually intersect when displayed. Each group of intersecting markers is then replaced with a single cluster marker that looks different. The cluster marker, when clicked, simply centres and zooms the map in on the markers whose icons previously intersected.
A more advanced approach to this problem might be SQL - same address = same coordinates...
GROUP BY or HAVING COUNT > 1 ... would let you create multi-record coordinates.
In fact - before you can cluster client-side, you need to send out the data first, which means transferring much more than required in this case, which results in higher loading times and higher RAM utilization client-side ...plus all the useless JS processing of the clusterer.
Client-side clustering is only recommend when the coordinates are close to each other, but not when they are absolutely identical.
Think about it...

How can I sort/group Salesforce leads by geography?

If I had lat/long data for all our leads in Salesforce, is there a way to write a query to group them, or say list all the leads within 10 miles of San Francisco, CA ?
[EDIT: Clarification]
I have thousands of leads with both a full address, and long/lats.
I want to build a query on these leads that will give me all of the leads near San Francisco, CA. This means doing GIS type work within salesforce.
I could of course filter specifically on city, or zipcodes or area code, but this presents some problems when trying to rollup a whole metro area.
Yes. You need to Reverse GeoCode them with a tool/service. In the past I have used Maporamas service but it was quite expensive and that was before Google maps and virtual earth existed so I am sure there is something cheaper(free) out there now.... Googling around I have found this and this
EDIT:
OK from What I understand you are trying to calculate the distance between 2 lat/long points. I would start by discounting the ones that where outside you sphere of (lets say) 10 miles. So from your central point you will want to get the the coordinates 10 miles, East, West, South and North. To do this you need to use the Great-circle distance formula.
From that point you have you Sales Force Data if you wish to break this data up further then you need to order the points by distance from the central point. To do this you need to use the Haversine formula
I am not sure what you language preference is so I just included some examples from SQL(mainly) and C#
Haversine Formula in C# and in SQL
Determine the distance between ZIP codes using C#
Great Circle SQL
Great Circle 2
Use GeoHash.org (either as a web service or implement the algorithm). It hashes your lat-long coords into a form that appears similar for nearby places. For example A may have a hash like "akusDf3af" and B might have a hash like "akusDf3b2" if they are nearby. Then do a SOQL query that looks for places starting with the same n characters as a known location. Your n will determine the radius of the lookup.
These are some great technical solutions that can provide very exact answers, but two things to consider:
geospatial proximity does not map neatly to responsibility
Ownership calculation seems to be done best through postal code lookups or other rules that don't allow for gaps or overlaps. Otherwise, you'll have two (or more) salespeople fighting over leads that are close to both of them, and ignore those leads that are far away from both of them.
So, if you're using geo-calculations like those above to assign ownership, just acknowledge the system will leak and create business rules to accomodate for that. But a simple postal lookup to define territories (as salesforce's own territory management feature does) might be better.
I'd suggest the problem we're trying to solve geospatially is not who owns which lead. Rather, given all the leads you own, which are nearby?
maps often offer more data per pixel than columnar reports
Again, geospatial data in a report may not be the best answer. A lead 50km away, but along a major road, is more interesting than another lead 50km away on the other side of a mountain or lake. Or a lead close to other leads is more interesting than a lead by itself.
A report can't show this, but a map can.
Salesforce has some great examples of Google Maps integrations. Instead of a columnar report called "My Nearby Leads", why not a visualforce page, with a google map inside? You're giving the user far more information than a columnar report could. They might like it better, and it's easier to implement than trying to calculate some of the equations above.
Just another perspective that may (or may not) be appropriate to the problem at hand.
This post is really old, but is showing up at the top of Google results, so I figured I would post some info to it anyways.
2 nice mapping tools are batchgeo.com and geocod.io. Geocod.io can even give you lat and long coordinates from an address.
If you just need a one time calculation, you can use Excel. Export all your leads with the lat and long. Then go to Google Maps and get the lat and long in decimal degrees for the city center of wherever you want to measure to.
Then use this formula in excel to calculate the distance between the coordinates in miles. Lat1dd and Long1dd are the coordinates for one point, and the lat2dd and long2dd are coordinate points for the other point.
=3963*ACOS(COS(RADIANS(90-lat1dd))*COS(RADIANS(90-lat2dd))+SIN(RADIANS(90-lat1dd))*SIN(RADIANS(90-lat2dd))*COS(RADIANS(long1dd-long2dd)))
After you run it, just sort the results from smallest to largest to get those results that are the closest.
I haven't done this next part yet, but conceptually it should work. We have a field that lists the major market each account is in. Example, Chicago IL. I am going to build a trigger or formula field that essentially says IF(Market="Chicago IL") then use X and Y for the lat and long. These will be hardcoded as the city center for that specific market. The query will then run each individual account's lat and long against the one from the city center to calculate a distance.
If you wanted to break the market into different zones, you could adjust your formula so it uses < and > on the lat and long fields. Everything less than X but greater than Y goes in Zone A, etc.
Hope this helps someone.