Thursday, May 19, 2016

Ionic create button to open google map or map app

The most simplest way without adding any extra plugin as below :-


 in controller : -

 $scope.mapOpen = function () {

              var address = '21, Jalan PJU 1/37, Dataran Prima, 47301 Petaling Jaya, Selangor, Malaysia';
              var url = '';

 if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {

             url = 'http://maps.apple.com/maps?q=' + encodeURIComponent(address);

}
else if (ionic.Platform.isAndroid()) {

            url = 'geo:?q=' + encodeURIComponent(address);
 }
else {

          //this will be used for browsers if we ever want to convert to a website
          url = 'http://maps.google.com?q=' + encodeURIComponent(address);

 }

 window.open(url, "_system", 'location=yes');

 }


 In Html : - <button class="button button-assertive" ng-click="mapOpen()"> button-assertive         </button>

No comments:

Post a Comment