I'm trying to find out if a point lies within my country boundary. I'm using this data set as my country boundary: http://eric.clst.org/wupl/Stuff/gz_2010_us_outline_5m.json
And currently I'm check this point [-97.5164,35.4676]
function(){
var pt = turf.point(origin);
return turf.inside(pt, gz_2010_us_outline_5m);
}
How do I setup my geojson boundary data with turfjs so that it can be combined into a polygon to check if the point falls inside?
Just use turfs http://turfjs.org/docs/#lineToPolygon which Converts (Multi)LineString(s) to Polygon(s).
Related
I am working on some Cab related app. But I have a problem that if my pick up location and drop location are same then how can I calculate the distance covered by the cab that time.
Currently I am calculating distance from one coordinates to another coordinates using the below mentioned code.
func calculateDistance(pickLat: String, pickLong: String, dropLat: String, dropLong: String) {
let coordinate0 = CLLocation(latitude: Double(pickLat)!, longitude: Double(pickLong)!)
let coordinate1 = CLLocation(latitude: Double(dropLat)!, longitude: Double(dropLong)!)
let distanceInMeters = coordinate0.distance(from: coordinate1) // result is in meters
print(distanceInMeters)
}
This is normal process I am doing. Please help me out.
For this you need to work on specific event. You need to start capturing the location from your taxi app when the taxi arrived at pickup and the ride is started. You must have events like ArrivedOnPickup , RideStarted,OnWay, Completed.
Just like #Lu_ Suggested start capturing the coordinates in an array till the ride is completed. On ride completion you get the distance by implementing
http://findnerd.com/list/view/How-to-calculate-distance-from-array-of-coordinates-in-iOS/17529/
Note: You can also use Google Direction api to draw path and get the distance but this will not ensure that you route taken by the driver and route provided by the google will be same
I got an array of location objects. ( latitude , longitude, location name).
Location is received from users gps from morning to evening.
Challenge:
I want to create trip by filtering the location objects.
For e.g.: trip 1 will contain location from one start point to another and trip 2 will contain...
User can make 2/3 trips per day.
Question:
How can I group that array containing closer(values) latitudes and longitudes in swift iOS ?
EDIT
Get the data from array if the user is traveling else leave them so that from that array i can make a trip
Any ideas highly appreciated.
I think there is no way like magic code in swift for that.
How I actually solve is by traditional solving technique.
I did made a for loop and inside made a checker (which checked if two consecutive elements got time interval > 30 minutes then add the collected array elements as object to main array .
If anyone searching for such then apply you own logic.
var closure:((_ sender:UIButton)->())? = nil
var closure:((_ sender:UIButton)->())? = nil
closure!(sender)
cell.closure = { (sender:UIButton) -> Void in
debugPrint("\(indexPath.row + 1)")
debugPrint(sender.tag)
}
I'm new to Mapbox GL JS, and am loving it! A couple of things I've run into when filtering markers on a GeoJson source that I'm wondering if someone can help me out with...here's a sample of my filter logic:
function applyFilters() {
var filters = ["all", ["==", "$type", "Point"]];
if (document.getElementById('filter1checkbox').checked)
filters.push(['==', 'property1', true]);
if (document.getElementById('filter2checkbox').checked)
filters.push(['==', 'property2', true]);
map.setFilter('markers', filters);
var llb = new mapboxgl.LngLatBounds(geojsonExtent(markers));
map.fitBounds(llb);
map.setCenter(llb.getCenter());
}
And here's my questions:
Once my filter is applied, is there a way to get a count of markers that matched the filter (Your search returned {X} items)?
When I use geojsonExtent to get the bounds of the marker collection, it doesn't seem to be taking the filter into account. Is there a way to get at the data behind the filter to pass into geojsonExtent?
Any advice on where to go for these items?
Once my filter is applied, is there a way to get a count of markers that matched the filter (Your search returned {X} items)?
You can get the number of filtered markers currently visible in the viewport by running
map.queryRenderedFeatures({layers: ['markers']).length
There is no way to get the total number of filtered markers across the whole map.
When I use geojsonExtent to get the bounds of the marker collection, it doesn't seem to be taking the filter into account. Is there a way to get at the data behind the filter to pass into geojsonExtent?
You can use queryRenderedFeatures for this too! (Note: this code is untested)
geojsonExtent({
type: 'FeatureCollection',
features: map.queryRenderedFeatures({layers: ['markers']).length
});
Looking google maps have located 4 points and have created a polygon with them in this way
insert into dummy_zip values (4,'prueba_directa','2016-04-13
08:08:15.973731','prueba_directa',1,1,100,'2016-04-13
08:08:15.973731',(SELECT
ST_Transform(ST_GeomFromText('MULTIPOLYGON(((37.986504
-1.121951,37.986741 -1.121243,37.985794 -1.120792,37.985608 -1.121479,37.986504 -1.121951)))',4326),900913)));
but when displayed on the map they are in a completely different location than where they should be?
Swap the axis order, which should be (X Y) or (long lat).
You can use ST_FlipCoordinates to fix any existing data.
I need to use a for loop to create a 2d array. So far "+=" and .append have not yielded any results. Here is my code. Please excuse the rushed variable naming.
let firstThing = contentsOfFile!.componentsSeparatedByString("\n")
var secondThing: [AnyObject] = []
for i in firstThing {
let temp = i.componentsSeparatedByString("\"")
secondThing.append(temp)
}
The idea is that it takes the contents of a csv file, then separates the individual lines. It then tries to separate each of the lines by quotation marks. This is where the problem arises. I am successfully making the quotation separated array (stored in temp), however, I cannot make a collection of these in one array (i.e. a 2d array) using the for loop. The above code generates an error. Does anybody have the answer of how to construct this 2d array?
You can do this using higher order functions...
let twoDimensionalArray = contentsOfFile!.componentsSeparatedByString("\n").map{
$0.componentsSeparatedByString("\"")
}
The map function takes an array of items and maps each one to another type. In this I'm mapping the strings from the first array into an array pf strings and so creating a 2d array.
This will infer the type of array that is created so no need to put [[String]].
Here you go...