It's a late Monday night and I'm at one of UC Berkeley's campus libraries studying with my friends for our upcoming midterm. After cramming for hours with practice exams, we are exhausted and decide to call it a day. I begin packing my bags, but then have a sudden realization: it is 11PM, my friends live on the other side of campus, and my off-campus dorm is three blocks away.
Well, three blocks can't be that bad of a walk, right?
Sure, the walk isn't too bad when walking in the middle of the day. But when you're a new student walking alone in the middle of the night and you're constantly emailed police reports of crime activity around campus, three blocks can feel like a treacherous journey.
The city of Berkeley's Crime Index Ranking is #4, meaning that Berkeley is only safer than 4% of all U.S. cities. Many UC Berkeley students have experiences similar to mine, regularly staying on campus until the evening to study or contribute to their extracurricular activities. These safety concerns extend to cities around the world, affecting everyone from college student to full-time employees.
Location is important. Our lives are important too, and navigating through any unfamiliar area can be dangerous, especially when walking alone in the evening. During my summer internship at the HERE Berkeley office, I had the opportunity to work with Vanasa Liu—another intern—and the Berkeley Design Office on a location based side project that utilizes HERE's location technology.
Safely, the iOS app ensuring pedestrian safety
Using the recently released HERE Freemium plan, we developed Safely, the iOS app that helps users route safely from start to destination. When users provide a starting location and destination, Safely calculates several routes that avoid areas with large amounts of crime. The following is a simplified demo of how we implemented some key features with the iOS Premium SDK using Swift.
HERE Maps and Positioning
Let's start by displaying the HERE map on the phone screen and tracking the user's location. We need to set up a NMAMapView and NMAPositioningManager within a UIViewController.
Now that we have a NMAMapView and NMAPositioningManager, we can set the NMAMapView to center on the user's location when the NMAPositioningManager initially updates.
Great! Now our map starts at wherever our user is. However, there may be cases when the user's position is lost while using the app. Let's handle whenever the app accidentally loses the user's locaton.
Setup for Routing
Now that we have the map and basic positioning set up, let's move onto the setup for calculating routes. The NMAPositioningManager is used to obtain the starting location for our routing. After we provide a destination, we can also add areas that should be avoided. Let's create a new function and instantiate a NMACoreRouter object to handle the routing.
In order to prevent our app from routing users into dangerous areas, we must provide a NMADynamicPenalty object, which provides restrictions while calculating routes. In the case of Safely, we created NMAMapPolygons around regions that experienced the highest crime rates according to Berkeley PD's Calls for Service Heat Map.
Before we start calculating routes, we must note the routing options that we want to avoid and instantiate a NMARoutingMode object. In the case of Safely, we wanted to find the fastest valid route and avoid all routing options that do not involve safe pedestrian travel. It may also be helpful to limit the maximum number of routes that we can retrieve.
Now we can start finding safe routes! Our NMACoreRouter object has a function that involves a completion block, in which we are able to access the routes that we have retrieved. For the first (fastest) route we retrieve, we set its color to green, set its z-index to 999 so it will be the frontmost route, and add the route to the mapView. For any other routes, we set its color to light gray and add it to the mapView.
The map should now display a green route with up to two alternative routes, all of which do not traverse through our NMADynamicPenalty object. With that, we have covered some of the most important features in HERE's iOS Premium SDK! To see how we put these features to use in our Safely app concept, check out the gif below.
Next steps for Safely?
Currently, Safely's scope is limited to using Berkeley PD's public datasets and focuses on HERE Routing. There is a lot to consider should this app continue in development. For example, what are some other HERE API features that could be implemented? HERE's iOS Premium SDK has a plethora of features to experiment with. Also, is the number of crime incidents truly the best indicator for safeness of an area? Places with larger population density, like major streets and intersections, would likely have more crime activity simply due to the greater number of people that choose to walk that way. A better statistic to consider could be the number of crime incidents relative to pedestrian traffic; however, pedestrian traffic is not readily available as a public dataset and can be difficult to obtain.
Technology continues to evolve, and we aspire to devise more and more ways to benefit society with novel ideas and solutions. Over the summer, Vanasa and I discovered a problem that has an effect on people all around the world. We took a concept from ideation through product design and multiple iterations. And with HERE's extensive location database and readily available APIs, we took this concept all the way to a functional prototype that routes users to their destinations safely. As developers continue to make the #SwitchToHERE, there's no limit to what we'll be using HERE's APIs for in the future.
Thank you to Vanasa and the Berkeley Design Office for your guidance and contributions to this project. And thank you Jayson DeLancey for reaching out to us. You can find my portfolio here: https://brandonhudavid.github.io/