Find places within the boundaries of given locations - ios

in my maps app i have to find the places (bank,ATM,cafe,bar..) inside bound of selected locations.Actually i have to get the places which are centre to the given locations.
for example i have 4 places a,b,c,d i have to get all banks inside bounds of these 4 places and have show them on map.
i can get nearest places for each location individually by using GooglePlaces API.but i need show places which are centre(approximately) to these 4 places.
please give me any suggestions how to do this or any example code or any other tutorials or links....
Thanks
Raki.

Your solution would be to take the average lat/lon of your points and then hit your Google API to get locations in that area. This average will be in the middle of however many coordinates you have. Example:
double totalLat = 0;
double totalLon = 0;
for(CLLocationCoordinate2D coordinate in coordinateArray)
{
totalLat += coordinate.latitude;
totalLon += coordinate.longitude;
}
// Use this average coordinate (which is the center of your points) to hit your Google API
CLLocationCoordinate2D averageCoordinate = CLLocationCoordinate2DMake(totalLat / coordinateArray.count, totalLon / coordinateArray.count);
Note: I haven't actually tested this, so don't just copy/paste, but it's the general idea.

You can always use the radius parameter defined in the Places API to get this information.
Please follow this Stack Overflow answer for more details.

Related

How To Detect A User Is Within Range Of An Annotation

So I am working on a project that includes many uses placing annotations all around a map. The annotation, (which is a custom image with a much larger circular range) appears on the screen and, ideally, I would like for a user to be:
Notified if they are within the range of a annotation
and
Not be allowed to place another annotation within the range of another one if the circular pins overlap by, say, more than 25%
I think this is a pretty unique question and should be fun for somebody to help out with, so have fun! Thanks everybody!
You can check the distance from each annotation using
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
This method measures the distance between the two locations by tracing
a line between them that follows the curvature of the Earth. The
resulting arc is a smooth curve and does not take into account
specific altitude changes between the two locations.
For more details refer Link
Try this:
let location = CLLocation(latitude: 1, longitude: 1)//Or user's location
let distance = location.distance(from: anotherLocation)
Edit:
As mentioned in the comments, you wanted to create an equidistant point. I suggest manually doing that:
Subtract the annotation's location from he user's location. Then add your distance back to the original one. For example:
The user's location = (1, 1)
The annotation's location = (3, 2)
Vertical difference would be 2
Horizontal difference would be 1
Then:
(3 + 2, 2 + 1)
Your result: (5, 3)
Now you would have two points (the one you just created and the user's location) at each end with a center point (original annotation)

Algolia: Search multiple geos simultaneously?

Is there any way to search for items within distance of a lat/long for multiple lat/longs simultaneously? E.g., to say "give me all results within 10 miles of 14.2342,-13.234234 AND 1.3234,4.56775"?
I currently only see the ability to search one set of coordinates at a time.
In its current version, the API only allows to pass one lat/long value at a time.
Nevertheless, it allows to pass multiple bounding boxes at the same time. That means that you could easily calculate the bounding boxe coordinates (see How to calculate the bounding box for a given lat/lng location?), and pass those to the search parameters.
You can find here https://www.algolia.com/doc/tutorials/geo-search a guide (+ sample code) showing how Geoloc search works. And more detail about the boundingBox parameters at https://www.algolia.com/doc/rest#param-insideBoundingBox

Delivery radius for a restaurant in Apple Maps

I'm trying to develop a delivery system for a restaurant, but I'm not sure how to approach this problem. The restaurant has five locations; four of them are in one state and the other is in a different state.
They only do deliveries for each location depending on how far it is; they also have setup certain limitations for each location.
My idea will be:
Fetch user's location on iOS (Accomplished)
Check if user location is inside of any Restaurant delivery radius. If so, set that location as the store, if not, just show a message that we don't delivery in their area.
Where I'm stuck
How can I define in Apple Maps the limits of Location 1, 2, 3, etc. (meaning what area will they be doing delivery to)?
Try setting the deliverable radius around the location of the restaurant. You can even draw an MKCircle to be fancy.
CLLocation * _storeLocation = [[CLLocation alloc] initWithLatitude:30.270135 longitude:-97.731270];
double deliverableRadius = 3 * 1609.34; // 3 miles (or the area they will deliver to)
MKCircle * circle = [MKCircle circleWithCenterCoordinate:storeLocation.coordinate radius:deliverableRadius];
[_mapView addOverlay:circle];
Once you have established the deliverable area, you can check to see if the see if the users location is within this area.
So I think a simple approach might be to simply check if the user is within a certain distance of a restaurant (ie "If I am less than 25 miles from a restaurant, then they will deliver to me").
First convert the address of the restaurant locations into gps coordinates. See Converting Place Names Into Coordinates for more info.
Next, calculate the distance between the user's location and the location of each restaurant and check if that distance less than the maximum delivery distance.
A formula for calcualating the distance between two points can be found here.

plotting latitude on to a (Mercator projection) SVG map

I want to convert (google sourced) longitude and latitude coordinates to x and y to place points on a SVG map
I can get the longitude converted to X but I can't nail latitude.
http://jsfiddle.net/chrisloughnane/an3BZ/17/
red dots = place holders
green dot = calculated position from longitude/latitude
I have read so much about Mercator projections and other projection systems API's I am now completely confused. I also followed Proj4JS library threads but couldn't find an example that was close to my task.
I attempted to emulate this solution, unfortunately I got something wrong.
Could someone please have a look at my jsfiddle and see if it's an obvious mistake.
The second test function secondconvert(latitude, longitude) (bottom of javascript pane) provides me with a reasonably accurate x coordinate i.e. if I manually enter the y coordinate b.ylat change to 265 it covers my left red dot place holder nearly perfectly.
I think I'm close, any help would be really appreciated.
tia.
Original SVG from here.
In your calculations of lattest and mapOffsetY inside secondconvert() you're using variable width where Raphael's solution uses worldMapWidth. Fixing that you get closer to the expected result, though still not precise.

mapping latitude and longitude values onto an image

i'm trying to geocode values and map them to a satellite image of a city (new york city to be precise). i've successfully done this before using a geospatial image of the world, and then mapped/scaled longitude and latitude values from the max lat/lng range (-90,90 & -180,180) to the max width and hight of the image (0,width & 0,height) which worked perfectly. i'm a bit confused how to do this to just a map of a city.
currently, i have a hi-res satellite image of new york city, and have positioned it so that it perfectly aligns with the map of new york city on Google Maps (i'm using their API to geocode my locations). i've attempted to get the top/bottom latitude values and left/right longitude values of the satellite image i'm using, and tried to scale any longitude/latitude values that needed to be mapped onto the image within this range. however, this didn't seem to work. is there another method i could use so that it would be possible to dynamically map lat/lng coordinates onto a satellite image of new york city?
this is essentially the image that i would like to map onto:
thanks.
If you know the image size and its geographic extent (lat/lon values), you can use something like:
x = imageWidth * ( pointLon - ImageExtentLeft ) / (ImageExtentRight - ImageExtentLeft);
y = imageHeight * ( 1 - ( pointLat - ImageExtentBottom) / (ImageExtentTop - mImageExtentBottom));
By the way, if you are using the Google Maps API to geocode your locations, why don't you use its functions to add markers directly to your map? (Maybe I didn't completely understand your case)
var latlng = new GLatLng(pointLat, pointLon);
map.addOverlay(new GMarker(latlng));
Hope it helps
You are engaging in a process called image registration or map rectification. There is a whole set of remote sensing dedicated to the equations for doing this.
Perhaps you can just start with this web site - it should basically do what you need
http://labs.metacarta.com/rectifier/ (dead link)
if not then maybe look at tools like QGIS or GRASS. If you have money and time you can also use ESRI ArcGIS desktop or ERDAS Imagine or IDRISI.

Resources