Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit system suppor #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Once the directions in between `destination` and `origin` has been fetched, a `M
| `precision` | `String` | `"low"` | The precision level of detail of the drawn polyline. Allowed values are "high", and "low". Setting to "low" will yield a polyline that is an approximate (smoothed) path of the resulting directions. Setting to "high" may cause a hit in performance in case a complex route is returned.
| `timePrecision` | `String` | `"none"` | The timePrecision to get Realtime traffic info. Allowed values are "none", and "now". Defaults to "none".
| `channel` | `String` | `null` | If you include the channel parameter in your requests, you can generate a Successful Requests report that shows a breakdown of your application's API requests across different applications that use the same client ID (such as externally facing access vs. internally facing access).
| `unitSystem` | `String` | `metric` | Specifies the unit system to use when displaying results. Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. For example, a route from "Chicago, IL" to "Toronto, ONT" will display results in miles, while the reverse route will display results in kilometers. You may override this unit system by setting one explicitly within the request's units parameter, passing one of the following values: `metric` specifies usage of the metric system. Textual distances are returned using kilometers and meters. `imperial` specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. ).
#### More props

Since the result rendered on screen is a `MapView.Polyline` component, all [`MapView.Polyline` props](https://github.com/airbnb/react-native-maps/blob/master/docs/polyline.md#props) – except for `coordinates` – are also accepted.
Expand Down
9 changes: 7 additions & 2 deletions src/MapViewDirections.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class MapViewDirections extends Component {
region,
precision = 'low',
timePrecision = 'none',
unitSystem = 'metric',
channel,
} = props;

Expand Down Expand Up @@ -174,7 +175,7 @@ class MapViewDirections extends Component {
}

return (
this.fetchRoute(directionsServiceBaseUrl, origin, waypoints, destination, apikey, mode, language, region, precision, timePrecisionString, channel)
this.fetchRoute(directionsServiceBaseUrl, origin, waypoints, destination, apikey, mode, language, region, precision, timePrecisionString, unitSystem, channel)
.then(result => {
return result;
})
Expand Down Expand Up @@ -227,7 +228,7 @@ class MapViewDirections extends Component {
});
}

fetchRoute(directionsServiceBaseUrl, origin, waypoints, destination, apikey, mode, language, region, precision, timePrecision, channel) {
fetchRoute(directionsServiceBaseUrl, origin, waypoints, destination, apikey, mode, language, region, precision, timePrecision, unitSystem, channel) {

// Define the URL to call. Only add default parameters to the URL if it's a string.
let url = directionsServiceBaseUrl;
Expand All @@ -236,6 +237,9 @@ class MapViewDirections extends Component {
if(timePrecision){
url+=`&departure_time=${timePrecision}`;
}
if (unitSystem) {
url+=`&units=${unitSystem}`;
}
if(channel){
url+=`&channel=${channel}`;
}
Expand Down Expand Up @@ -351,6 +355,7 @@ MapViewDirections.propTypes = {
region: PropTypes.string,
precision: PropTypes.oneOf(['high', 'low']),
timePrecision: PropTypes.oneOf(['now', 'none']),
unitSystem: PropTypes.oneOf(['metric', 'imperial']),
channel: PropTypes.string,
};

Expand Down