snap to road for apple maps

2019-08-09 18:17发布

I have a project which is constrained to working with apple maps, corelocation and apple's mapkit -- 3rd party interfaces aren't allowed.

I need to display a map view showing the user's current location (standard blue dot) and simultaneously place a pin on the road nearest the user's current location -- a 'snap to road' which is a best estimate of the user's nearest location.

I know how to retrieve the user's current address and use the returned street name and address, but i don't know how to add the pin to the resulting street in mkmapview. I've looked at the mkdirectionsrequest but am unsure how to adapt the returned data to solve this problem.

thanks in advance for your help!

2条回答
萌系小妹纸
2楼-- · 2019-08-09 18:38

I think you can get the road-snapping done by Location Services, by adjusting the location service mode.

Apple's Developer docs on CLLocationManager offer four 'Activity' modes:

  • Other ~ unspecified
  • Automotive ~ in a car, truck, road vehicle
  • Fitness ~ pedestrian related activity
  • OtherNavigation ~ trains, planes, boats

(no comment about the ambiguity between the first and fourth... there's a bit more detail in the developer docs too than my few-word summaries above)

Basically you set CLActivityType to CLActivityTypeAutomotiveNavigation, and it will do sensible things on the assumption you're in a road vehicle. From what I've seen, this more aggressively snaps to vehicular roads, though you're still limited by the fidelity of Apple's maps.

查看更多
Emotional °昔
3楼-- · 2019-08-09 18:49

For a snap to road feature you need the sequence of latitude and longitude coordinates of that street. You usually never get that vector info, because the owner of that vector data (TomTom and Nokia) do not allow that.

Only OpenStreetMap based data is free, and vector data is available.

ios uses TomTom data, and as expecdted you will not get the coordinates of the polyline of a street.

查看更多
登录 后发表回答