Search code examples
google-maps-api-3mauimobile-application

How to use google directions API in MAUI App?


How to use Google Map Route/Direction APIs in MAUI App? Is it possible to use the same API key from https://console.cloud.google.com/apis/credentials?project=xxxxxxxxx ? Or is it a paid service? We need to show the shortest route in the MAUI app. So how can we achieve this?


Solution

  • You can use the same API key for multiple APIs. However, for security purposes and setting API key restrictions, it's recommended to use a separate API key for each, check out the API key security docs here: https://developers.google.com/maps/api-security-best-practices

    You can use the Directions API and/or Distance matrix API for this purpose: https://developers.google.com/maps/documentation/directions https://developers.google.com/maps/documentation/distance-matrix

    Directions API will give you the quickest full route and the Distance Matrix API will give you the distance and duration of routes.

    If you wish to use the Browser/JS version of these APIs, check out these docs here: https://developers.google.com/maps/documentation/javascript/directions

    For MAUI specific docs, take a look here: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/map#distance:~:text=map%20app%20with-,directions,-The%20native%20maps

    However, if you wish you can use a Web Service API within the mobile application. You will have to set up a proxy server or obfuscation for full API key security: https://developers.google.com/maps/api-security-best-practices#ip-address-best-practices-table