code map
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
// Ionic Starter App // angular.module is a global place for creating, registering and retrieving Angular modules // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) // the 2nd parameter is an array of 'requires' // include ngCordova angular.module('starter', ['ionic', 'ngCordova']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if (window.StatusBar) { StatusBar.styleDefault(); } }); }) // $cordovaGeolocation // $ionicLoading .controller('MapController', ['$scope', '$cordovaGeolocation', '$ionicLoading', function($scope, $cordovaGeolocation, $ionicLoading) { var myLocation = new google.maps.LatLng(43.07493,-89.381388); var map = new google.maps.Map(document.getElementById('map'), { mapTypeId: google.maps.MapTypeId.ROADMAP, center: myLocation, zoom: 15 }); console.log(map) $scope.map = map; $scope.locate = function() { var posOptions = { timeout: 10000, enableHighAccuracy: true }; $ionicLoading.show(); $cordovaGeolocation .getCurrentPosition(posOptions) .then(function(position) { $ionicLoading.hide(); var lat = position.coords.latitude; var lng = position.coords.longitude; alert("Got position: " + lat + ", " + lng); var myLocation = new google.maps.LatLng(lat, lng); var ThewesLocation = new google.maps.LatLng(13.7723862, 100.5006843); var BCCLocation = new google.maps.LatLng(13.7622442, 100.5113833); var map = new google.maps.Map(document.getElementById('map'), { mapTypeId: google.maps.MapTypeId.ROADMAP, center: myLocation, zoom: 15 }); var marker = new google.maps.Marker({ map: map, position: myLocation }); marker = new google.maps.Marker({ map: map, position: ThewesLocation }); marker = new google.maps.Marker({ map: map, position: BCCLocation, }); }, function(err) { $ionicLoading.hide(); if (error.code == PositionError.PERMISSION_DENIED) { alert("Permission denied. check setting"); } else if (error.code == PositionError.POSITION_UNAVAILABLE) { alert("Cannot get position. May be problem with network or can't get a satellite fix."); } else if (error.code == PositionError.TIMEOUT) { alert("Geolocation is timed out."); } else { alert(error.message); } }); } }]) |
Recent Comments