In my app I want to highlight certain roads, which can easily be achieved just by drawing polylines on top of the roads. (I am using the Google Maps SDK, by the way). However these polylines won't follow the road's geometry, they will just connect two coordinates with a straight line. (I have a coordinate for the start of the road which I want to highlight and the end of it). The coordinates won't change, the same roads will be highlighted through out the whole time in the app.
The question is: Is there a way I could draw these polylines not to be straight but to follow the road's geometry? If it's not possible in the SDK, is there a tool on the internet which will connect two coordinates following the roads between them? Because if there is, than I could get the coordinates of those poylines and parse them in my app.
Cheers!
as #Fabian has suggested, if you have a small set of polylines to show in your app, and your app works mostly offline, it would be better to get all the polylines during the development. And there are two ways:
1) through the direction API, you might able to skip all the implementation by using the WEB API, which is meant for webserver.
https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=highways&mode=bicycling&key=API_KEY
2) or, with the Snap to Road API, which might gives you a better control over your route compare to the direction API. This API is meant to fix the pool GPS data you get from the sensor and snap those on the road.
Related
I am working on an app where I give direcctions in a country. Directions in that country is not available from apple so i decided to use google api on an apple map. However as you can see from my sceenshot. Although I find the location on my iphone mmap i just get straight lines versus following the route that google does.
Does this have anything to do with using google API on Apple Maps? I have no reason why this is happening.
this is the link I pass to the web from my app
http://maps.googleapis.com/maps/api/directions/json?origin=15.299503,-61.387292&destination=Rosalie+Bay+Resort,+Rosalie,+Saint+David+Parish,+Dominica&sensor=true
If you are using MKMapView, you should check out the following examples:
http://www.meonbinary.com/2014/02/route-directions-with-ios7-mapkit-and-google-maps-api
http://sugartin.info/2011/10/12/drawing-route-on-google-map-mkmapview/
If you are using GMSMapView, check out this stack question: Drawing Route Between Two Places on GMSMapView in iOS
I know this is an old thread, but you are not getting 'weird' polylines..
You drawn them manually from the steps.
If you look closely on the right map, you see the 'white' dots ?
Your polylines follow these dots, you can name them the direction steps.
I have the same issue when I simulate the directions :) That's how I got here.
For just drawing, draw routeRequest.routes[0].polyline directly to the map, and it looks good :)
I see some ways to do it:
1) Draw using OpenGL programmatically.
2) Draw using QuartzCore and CoreAnimation programmatically.
3) Draw map in AutoCad and then somehow connect it to iOS.
4) Draw map using SVG.
Requirments are supporting pathfinding and gps navigation.
For first 2 ways I think that it's expensive in terms of performance way, redraw all elements on scaling; and I don't think that this way may have GPS-navigation support.
Using AutoCad pictured maps is hard to understand for me how to connect it with graphs\paths for pathfinding.
My colleagues will develop this app on web using SVG. I found it - https://github.com/SVGKit/SVGKit , but still have no idea how it will support pathfinding and navigation.
I would appreciate any help.
Generally there are two types of map application:
A) They display a map, (with or without a user position) without needing to calculate a path like a navigation system does (see point B)
B) Application that use the vectors of a map and calculate something: e.g to find a best path. The shortest connection, e.g A navighation system , etc.
Application for A) are usually less complex then that of B), because the vectors can be somewhat inacurate, have no conections, have small gaps, have no logic between the edges, etc.
1) To only display a building map, you would only need a list of edges. (An edge is pair of coordinates (x1,y1) - (x2,y2). How ever you get that. E.g MapInfo Professional format mif/mid.
Or even you could dispaly a pdf that contains the map of the builing. Right with the built in PDF View, (also with SVG but more difficult).
Things get much more complicated if it is not a relative map, but also a map that is positioned with an reference coordinate system, like latitude/longitude (WGS84).
In that case you would use a Tool (mapInfoProfessional, to import AutoCad DXF Files, and apply 3 GPS measured reference points at the corner of the house, and convert that to LatLong WGS84 coordinates system.
With ios you cannot measure that 3 Points because you cannot average a position, ios stops sending when you are standing still at one corner of the house.
You could try to extract the positions from a google earth satellite foto if you are living in a region where google Sattelite fotos have high resolution. (But this might violate the license conditions of that Satellite Foto provider (Topic: derived data))
Finally you now have a list of edges in Lat Lon coordinate System.
For Displaying I personally would either do with 1) OpenGL) or 2) Quartz2D.
Now the Path finding part.
Probaly you need a second "map" that defines the possible paths inside the building.
This structure must be a connect graph (points with connected neighbours).
Computer games do it that way. (Some even allow you to display that path in developper mode)
The path can be drawn, in a different layer of the floor plan. But this path
has higher requirements: No gaps are allowed, all must be perfect connected.
Call that layer "Path" and export it as own plan.
Now use only this path layer, and import, and create a graph of nodes with connect neighbours.
Use Dijkstra Algo to search for shortest path.
I'm building an iPad app that will present a screen-by-screen walkthrough of directions sourced from Google's Directions API. I'd like to track the user's progress through physical space using CoreLocation and update the screens to follow the user, similar to most directions applications.
My initial idea is something along these lines:
For each step in the directions, grab the corresponding polyline
When CoreLocation updates, check whether the lat/long pair are within some delta of some point on the polyline (ie, iterate over all the points on the polyline).
If the location is within the polyline, stay on the same screen
If not on the polyline, check whether the user is within the same delta of some subset of the polyline for the next step (say 10 points) and, if so, advance to the next screen.
If not on the next polyline, alert the user that they've left the route.
This seems inefficient and not particularly accurate... Are there better ways to do this?
I have a question about the MKMapView component. I saw that on the native "Map" iOS app, we can draw the roads between different points and we can display the traffic for those roads. Well, that's exactly what I want to do for my app :)
So, I have two questions :
1) Firstly, how can I draw roads on a map. I read a lot of things about MKOverlay, about some samples which do that with JavaScript in UIWebView but what's the best way to do this ?
2) How can I know the traffic on a particularly road ? In order to draw the road in green, orange or red.
Thanks a lot !
Regards,
Sébastien ;)
Unfortunately by now CLGeocoder class from iOS 5 is just supporting to process address to geolocation transformation and reverse. It means to find address around the geocode you have or to find geocode of the address you provide. There are no possibilities access road graph to create routes (to select and draw roads precisely) and moreover to control traffic on the exact place. The only things you can do with standard tools is to draw overlays on the MKMapView with your own data.
To achieve the results you want I would offer to use the third party resources, Google Maps API for example, and use UIWebView to present a customized map. Google Maps JavaScript API v3 TrafficLayer
I'm trying to develop a mini "Around Me" like using camera, compass and location. I would like to display place's images on my screen.
For the moment I have my location and my orientation with compass. I would like to know how can I determine the position of the place I want to display.
Thanks for your help ;)
Once you have relative distance and bearing, which you can determine from two points in the same coordinate space using algorithms found on this page, figuring out where a known coordinate is with respect to a known viewpoint is basically a perspective projection, the math is outlined on this Wikipedia article. The rotation of the camera is given by the compass, and the tilt by the accelerometer (the position is of course, GPS).
I'm trying to find a better document - there are a couple of extra things to consider - like the camera parameters etc, but this is a good starting point.
If it's too involved (like if you're not comfortable with rotation matrices) we can break it right down to the simple trig.
The code in the iPhone ARKit project does this, and quite a bit more. While you may not be able to use their complete library, it is a great reference on the subject of augmented reality.
Check out 3DAR, it lets you add an AR view to a MKMapView app very easily. There's a video tutorial on this process, as well as some sample code, on the 3DAR site, www.3dar.us
You can create a location based AR app in Junaio. It's an AR browser. Free to use and deploy in (as long as it's not a custom app and in Junaio).