How to create bounder for GMSMarker












1















I have two GMSMarker were one of the is moving and the other is not and I want to create something smilier to geofencing where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,



I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?



can the GMSCircle be used to do so?










share|improve this question





























    1















    I have two GMSMarker were one of the is moving and the other is not and I want to create something smilier to geofencing where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,



    I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?



    can the GMSCircle be used to do so?










    share|improve this question



























      1












      1








      1








      I have two GMSMarker were one of the is moving and the other is not and I want to create something smilier to geofencing where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,



      I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?



      can the GMSCircle be used to do so?










      share|improve this question
















      I have two GMSMarker were one of the is moving and the other is not and I want to create something smilier to geofencing where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,



      I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?



      can the GMSCircle be used to do so?







      ios swift google-maps geofencing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 7:39









      Kaushik Makwana

      854422




      854422










      asked Jan 1 at 6:41









      NoufNouf

      308215




      308215
























          2 Answers
          2






          active

          oldest

          votes


















          2














          Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.



          var selectedPlace: GMSPlace? 
          let rect = GMSMutablePath()


          func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
          print("Place name: (place.name)")
          showPin(myPlace: place)
          dismiss(animated: true, completion: nil)
          }


          func showPin(myPlace: GMSPlace){
          mapView.clear()
          createArea()
          selectedPlace = myPlace
          print((selectedPlace?.coordinate)!)
          if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
          {
          print("YES: you are in this polygon.")

          }else{
          print("You do not appear to be in this polygon.")
          }


          func createArea(){
          // Create a rectangular path

          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
          rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
          rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
          rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
          rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
          //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
          rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
          rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

          // Create the polygon, and assign it to the map.
          let polygon = GMSPolygon(path: rect)
          polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
          polygon.strokeColor = .black
          polygon.strokeWidth = 2
          polygon.map = mapView
          }


          //CLLocationManager Delegates



          func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
          print("Start Monitoring Region")

          }

          func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
          print("Determine Region State")
          }

          func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
          print("Entered Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
          print("Exited Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
          print("Failed Monitoring Region")
          }





          share|improve this answer
























          • if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

            – Nouf
            Jan 3 at 7:08











          • If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

            – Yogesh Tandel
            Jan 3 at 7:43



















          0














          Have you tried CLRegion?



          create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.



          and for CLLocationManger you can start monitoring for region.






          share|improve this answer
























          • same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

            – Nouf
            Jan 3 at 7:13











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993519%2fhow-to-create-bounder-for-gmsmarker%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.



          var selectedPlace: GMSPlace? 
          let rect = GMSMutablePath()


          func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
          print("Place name: (place.name)")
          showPin(myPlace: place)
          dismiss(animated: true, completion: nil)
          }


          func showPin(myPlace: GMSPlace){
          mapView.clear()
          createArea()
          selectedPlace = myPlace
          print((selectedPlace?.coordinate)!)
          if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
          {
          print("YES: you are in this polygon.")

          }else{
          print("You do not appear to be in this polygon.")
          }


          func createArea(){
          // Create a rectangular path

          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
          rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
          rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
          rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
          rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
          //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
          rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
          rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

          // Create the polygon, and assign it to the map.
          let polygon = GMSPolygon(path: rect)
          polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
          polygon.strokeColor = .black
          polygon.strokeWidth = 2
          polygon.map = mapView
          }


          //CLLocationManager Delegates



          func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
          print("Start Monitoring Region")

          }

          func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
          print("Determine Region State")
          }

          func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
          print("Entered Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
          print("Exited Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
          print("Failed Monitoring Region")
          }





          share|improve this answer
























          • if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

            – Nouf
            Jan 3 at 7:08











          • If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

            – Yogesh Tandel
            Jan 3 at 7:43
















          2














          Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.



          var selectedPlace: GMSPlace? 
          let rect = GMSMutablePath()


          func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
          print("Place name: (place.name)")
          showPin(myPlace: place)
          dismiss(animated: true, completion: nil)
          }


          func showPin(myPlace: GMSPlace){
          mapView.clear()
          createArea()
          selectedPlace = myPlace
          print((selectedPlace?.coordinate)!)
          if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
          {
          print("YES: you are in this polygon.")

          }else{
          print("You do not appear to be in this polygon.")
          }


          func createArea(){
          // Create a rectangular path

          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
          rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
          rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
          rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
          rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
          //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
          rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
          rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

          // Create the polygon, and assign it to the map.
          let polygon = GMSPolygon(path: rect)
          polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
          polygon.strokeColor = .black
          polygon.strokeWidth = 2
          polygon.map = mapView
          }


          //CLLocationManager Delegates



          func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
          print("Start Monitoring Region")

          }

          func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
          print("Determine Region State")
          }

          func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
          print("Entered Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
          print("Exited Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
          print("Failed Monitoring Region")
          }





          share|improve this answer
























          • if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

            – Nouf
            Jan 3 at 7:08











          • If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

            – Yogesh Tandel
            Jan 3 at 7:43














          2












          2








          2







          Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.



          var selectedPlace: GMSPlace? 
          let rect = GMSMutablePath()


          func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
          print("Place name: (place.name)")
          showPin(myPlace: place)
          dismiss(animated: true, completion: nil)
          }


          func showPin(myPlace: GMSPlace){
          mapView.clear()
          createArea()
          selectedPlace = myPlace
          print((selectedPlace?.coordinate)!)
          if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
          {
          print("YES: you are in this polygon.")

          }else{
          print("You do not appear to be in this polygon.")
          }


          func createArea(){
          // Create a rectangular path

          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
          rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
          rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
          rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
          rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
          //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
          rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
          rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

          // Create the polygon, and assign it to the map.
          let polygon = GMSPolygon(path: rect)
          polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
          polygon.strokeColor = .black
          polygon.strokeWidth = 2
          polygon.map = mapView
          }


          //CLLocationManager Delegates



          func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
          print("Start Monitoring Region")

          }

          func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
          print("Determine Region State")
          }

          func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
          print("Entered Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
          print("Exited Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
          print("Failed Monitoring Region")
          }





          share|improve this answer













          Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.



          var selectedPlace: GMSPlace? 
          let rect = GMSMutablePath()


          func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
          print("Place name: (place.name)")
          showPin(myPlace: place)
          dismiss(animated: true, completion: nil)
          }


          func showPin(myPlace: GMSPlace){
          mapView.clear()
          createArea()
          selectedPlace = myPlace
          print((selectedPlace?.coordinate)!)
          if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
          {
          print("YES: you are in this polygon.")

          }else{
          print("You do not appear to be in this polygon.")
          }


          func createArea(){
          // Create a rectangular path

          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
          rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
          rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
          rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
          rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
          //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
          rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
          rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
          rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

          // Create the polygon, and assign it to the map.
          let polygon = GMSPolygon(path: rect)
          polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
          polygon.strokeColor = .black
          polygon.strokeWidth = 2
          polygon.map = mapView
          }


          //CLLocationManager Delegates



          func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
          print("Start Monitoring Region")

          }

          func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
          print("Determine Region State")
          }

          func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
          print("Entered Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
          print("Exited Monitoring Region")
          }

          func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
          print("Failed Monitoring Region")
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 5:02









          Yogesh TandelYogesh Tandel

          7781812




          7781812













          • if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

            – Nouf
            Jan 3 at 7:08











          • If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

            – Yogesh Tandel
            Jan 3 at 7:43



















          • if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

            – Nouf
            Jan 3 at 7:08











          • If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

            – Yogesh Tandel
            Jan 3 at 7:43

















          if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

          – Nouf
          Jan 3 at 7:08





          if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case

          – Nouf
          Jan 3 at 7:08













          If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

          – Yogesh Tandel
          Jan 3 at 7:43





          If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.

          – Yogesh Tandel
          Jan 3 at 7:43













          0














          Have you tried CLRegion?



          create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.



          and for CLLocationManger you can start monitoring for region.






          share|improve this answer
























          • same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

            – Nouf
            Jan 3 at 7:13
















          0














          Have you tried CLRegion?



          create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.



          and for CLLocationManger you can start monitoring for region.






          share|improve this answer
























          • same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

            – Nouf
            Jan 3 at 7:13














          0












          0








          0







          Have you tried CLRegion?



          create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.



          and for CLLocationManger you can start monitoring for region.






          share|improve this answer













          Have you tried CLRegion?



          create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.



          and for CLLocationManger you can start monitoring for region.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 10:44









          Akash SonejiAkash Soneji

          28111




          28111













          • same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

            – Nouf
            Jan 3 at 7:13



















          • same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

            – Nouf
            Jan 3 at 7:13

















          same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

          – Nouf
          Jan 3 at 7:13





          same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track

          – Nouf
          Jan 3 at 7:13


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993519%2fhow-to-create-bounder-for-gmsmarker%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          Npm cannot find a required file even through it is in the searched directory