1

I am building a JS app using cordova. I want to open google maps application when user clicks on link.

code -

  $window.location.href =  'comgooglemaps://maps.google.com/maps?saddr=My+Location&daddr=' +  destinationAddress

destination address is address of the place.

Now the above code works fine on ios but google maps doesnt open on android. From documentation it looks like comgooglemaps is iOS specific protocol

I have also tried geo urls mentioned in this Android - launch google map via web url as follows

<a href="geo:53,-9?saddr=(53,-9)&daddr=(42,4)">Click here for route maps</a>

It opens google map application but doesnt show the route.

Is there anything that will work on both android and iOS

Community
  • 1
  • 1
Coder
  • 3,090
  • 8
  • 49
  • 85

1 Answers1

2

I achieved this by the following javascript code, after a lot of research for our project we found that simply calling the maps.google.com works well for all:

1) Android
2) iOS
3) Web Browsers... :)

$scope.showMap = function () {
           var link = ""+"http://maps.google.com/maps?saddr="+$scope.slat+","+$scope.slon+" &daddr="+$scope.dlat+","+$scope.dlon;
            // $location.path(link);
            window.location = link;
        }

where:
$scope.slat = source latitude coordinates
$scope.slon = source longitude coordinates
$scope.dlat = destination latitude coordinate
$scope.dlon = destination longitude coordinates

The code has been tested and works fine in:
iPhone 4,
iPad,
iPad 3,
Moto E,
Sony Ericsson Xperia,
Moto G

Feature
The best thing about this is, the device by default will pick up the google maps app if installed, else it will open in the google chrome browser, which by default comes in all android devices.

Kailas
  • 7,350
  • 3
  • 47
  • 63
  • hey, this code snippet works from my laptop browser, but not from my mobile phone (Moto G2). My laptop browser asks me for location permission, while my mobile does not. anything I have to add there to bring it to work? – MojioMS Jun 23 '17 at 11:05