Objective C: How to list set of locations with the nearest geolocation - objective-c

I have compiled a list of locations with latitude and longitude information. Can I check what is the best approach to filter and populate the list of "nearest" geolocations in a table and mapview based on my current location? (or a destination entered by a user). Also is it also possible to indicate what is the radius I am interested in? e.g. only select all the nearest bookstores within 5km from my location etc
Appreciate your advice on this
Zhen Hoe

Maybe I'm missing something, but why don't you just add your locations to a mapView, and center the map on the user's current location or whereever they want? MapKit will do all the calculations for you, and only show the ones near the center. The user can set their own radius by zooming in and out. MapKit is highly optimized for exactly this purpose, that's how you can see the "rain of pins" in real time.
Update:
You can also go the other way: once you have the annotations on the map, you can query the map for those annotations that are in the visible region with:
- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect
From the docs:
This method offers a fast way to retrieve the annotation objects in a particular portion of the map. This method is much faster than doing a linear search of the objects in the annotations property yourself.

You may find - (CLLocationDistance)distanceFromLocation:(const CLLocation *)location to be very useful
http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation:

The haversine formula is frequently used to in navigation for calculating distances between coordinates. This is a pretty decent resource for distance calculations, and even has a code sample for haversine (though it is in Javascript).
If your list of locations is relative small (hundreds, even), you can probably just iterate through the whole list and calculate the distance between each place against current location.

Related

How can I render 19451 circles on Rect Native map efficiently?

I have 19451 points exported by coordinates in a JSON file. I am trying to render them in an efficient way on the map with circles. How can I achieve this? It is the first time I am using https://github.com/react-native-maps/react-native-maps with expo, so I am not that experienced in using maps services. I don't even know where to start from. I was thinking of something like rendering the points dynamically, based on whether one point is to be found in the region of the map that is currently shown on the screen, although I have no idea how to actually achieve this. The first thing I tried was to obviously render them at once: it takes ages and it is very buggy!
You have several options:
Use some kind of clustering when there are multiple circles in the same area, for example when you're zoomed out. Have a look at react-native-maps-clustering. Performance wise is decent enough but it may lag on older devices.
When you go over a zoom level you can limit the number of circles you draw, I guess they overlap anyways. When your limit has been reached, you can display some warning to let the user know that the number of circles was limited and he should zoom in. From my experience, drawing max 50 custom markers was the upper limit to avoid lag on older devices. With circles, that limit might be different.
Manually filter your data and decide whether the circle belongs to the current viewport (visible part of the map) or not.
Some code would help me to give you some more hints.

Allow only a specific country to be shown in react-native-maps

I am using react-native-maps in my React Native project and I want the map to show only Germany and dhe user should zoom in and out up to a certain level but always withing Germany. I don't want the user to be able to navigate to other countries.
I checked the documentation but I didn't find anything related to my problem. Is there any way to achieve this? Thanks!
As far as I'm aware, you'll really need to 'bodge' this as it's not really true functionality of native maps.
You can limit the maxZoom level, to ensure that they cannot zoom passed a certain point - this will help with zooming. As for scrolling outside of a certain area - you can hitch onto the onDrag event, and check the lat and lon object. If the coordinates are outside a specific boundary, you can take the user back to a specified location - or present a user error? Geo fencing seems like it could be a part of this also.
Apart from theoretical - I'm afraid I've never done this, so cannot show you any implementation.

GoogleMaps lag at a large number of markers

I apologize in advance for my English.
I have in the application of more than 5000 coordinates.
These coordinates point to the objects in all the earth.
The fact that I add all at once to the map coordinates (marker), and the map is very lag because of this!
5-6 FPS when scrolling the map.
How do I add markers for the current location (the camera), and if I scroll the map, these markers to remove, and add new to the new location (the camera).
I know there is a function idleAtCameraPosition, but how to get a list of coordinates of the array (MutableArray), which is included in the camera? How to keep track of it?
I do not understand this. Can someone already did one of you is in your project?
I hope you understand that I want to convey to you.
You might want to check Marker Clustering:
By clustering your markers, you can put a large number of markers on a map without making the map hard to read. The marker clustering utility helps you manage multiple markers at different zoom levels.
When a user views the map at a high zoom level, the individual markers show on the map. When the user zooms out, the markers gather together into clusters, to make viewing the map easier.
To have some insights about loading too many marker, try reading the article about Too Many Markers!
Some applications are required to display a large number of locations or markers. Naively plotting thousands of markers on a map can quickly lead to a degraded user experience. Too many markers on the map cause both visual overload and sluggish interaction with the map. To overcome this poor performance, the information displayed on the map needs to be simplified.
Hope this helps!

Convert a Lat/Lon coordinate on a map based on preset coordinates

First off, I am not sure if this is the right place so I apologize if this belongs elsewhere - please let me know if it does. I am currently doing some prototyping with this in VB so that's why I come here first.
My Goal
I am trying to make a program to be able to log different types of information for a video game that I play. I would like to be able to map out the entire game with my program and add locations for mobs, resources, etc.
What I have
The in game map can be downloaded so I have literally just stuck this in as a background image on the form (just for now). The map that I get downloaded though is not exactly as the map appears in the game though since the game will add extra water around everything when scrolling around. This makes it a bit tricky to match up where the origin for the map is in game compared to where it would be on the downloaded map.
The nice thing though is that while I am in the game I can print my current coordinates to the screen. So I thought that maybe I can somehow use this to get the right calculation for the rest of the points on the map.
Here is an example image I will refer to now:
In the above map you will see a dotted bounding box. This is an invisible box in the game where once you move your mouse out of the longitude and latitude points will no longer show. This is what I refer to above when I mean I can't find the exact point of origin for the in game map.
You will also see 2 points: A and B. In the game there are teleporters. This is what I would use to get the most accurate position possible. I am thinking I can find the position (in game) of point A and point B and then somehow calculate that into a conversion for my mouse drag event in VB.
In VB the screen starts at top-left and is 0,0. I did already try to get the 2 points like this and just add or subtract the number to the x and y pixel position of the mouse, but it didn't quite line up right.
So with all this information does anyone know if it is possible to write a lon/lat conversion to pixels based on this kind of data?
I appreciate any thoughts and suggestions and if you need any clarification of any information I have posted please let me know and I will be happy to expand on it. I am really hoping I can get this solved!
Thanks!
EDIT:
I also want to mention I am not sure if there is an exact pixel to lat/lon point for the in game map. I.e. the in game map could be 1 pixel = 100 latitude or something. So I might also need to figure out what that conversion number is?
Some clarifications about conversion between the pixel location to 'latitude and longitude'.
First the map in your game is in a geometry coordinate system, which means everything lies in 2D and you can measure the distance between two points by calculate the pixel position.
But when we talk about longitude and latitude, we are actually talking about a geography coordinate system, which is a '3D' model of the sphere oabout the surface of the earth. All the maps on earth are abstracted from 3D to 2D through one step called projection. Like google maps or your GPS. In this projection process, the 3D model converted to 2D model but there is always some part of the map will be tortured, so that same distance in pixels on a map could be different in length in reality.
So if you don't care about the accuracy then you can consider the geometry point as geography point. Otherwise, you need to implement some GIS library to handle the geodesic distance and calculate the geography point based on the projection coordinate system.

Convert pixel point to Latitude and Longitude

I am trying to create a custom map for iOS. For the time being I am using Openstreetmap images for the custom map app.
Now what I want is to convert the pixel point to Latitude and Longitude value at a particular zoom level. I am finding out the tile(pixel point) in which I clicked. I need to find out the Lat and Long of that particular point. How this can be calculated? Is there any general formula to find the Lat & Long from pixel point.
Thanks in advance
Do you know about route-me (https://github.com/route-me/route-me)? It is an open source iOS map library. I use a fork of this library found at https://github.com/Alpstein/route-me. These libraries provide the projections you are looking for and might even provide other functionalities you would have to implement yourself otherwise.