omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Removing custom pins with Map API

    Pythonista
    2
    21
    3626
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RocketBlaster05
      RocketBlaster05 last edited by

      Hello! I am very new to objc and have been attempting to mess around with the Python 3 mapkit omz posted. I simply want to change the code so that when long pressed is activated it only removes the 'dropped pin' pin on the map. Since the dropped pin is not originally on the map, it also would need to be bypassed for the first time the pin is dropped. If anybody could show me the necessary modifications to the code I would appreciate it. Thanks!

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @RocketBlaster05 last edited by cvp

        @RocketBlaster05 if I correctly understand, try this to add or remove a pin by a long press

        def long_press_action(sender):
        	# Add a pin when the MapView recognizes a long-press
        	c = sender.point_to_coordinate(sender.long_press_location)
        	if len(sender.mk_map_view.annotations()) == 1:
        		sender.remove_all_pins()
        	else:
        		sender.add_pin(c[0], c[1], 'Dropped Pin', str(c), select=True)
        	sender.set_center_coordinate(c[0], c[1], animated=True)
        
        RocketBlaster05 1 Reply Last reply Reply Quote 0
        • RocketBlaster05
          RocketBlaster05 last edited by

          Once again you are correct! Thanks once again!

          1 Reply Last reply Reply Quote 0
          • RocketBlaster05
            RocketBlaster05 @cvp last edited by

            @cvp Now that I have this working, do you know a way I could make it remove only one pin? Sorry I'm like brand new to objc. Thanks!

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @RocketBlaster05 last edited by cvp

              @RocketBlaster05 said:

              remove only one pin

              Sorry but I don't understand, there is only one pin...

              Do you want to have more than one pin and to be able to remove only one?

              RocketBlaster05 2 Replies Last reply Reply Quote 0
              • RocketBlaster05
                RocketBlaster05 @cvp last edited by

                @cvp yes.

                1 Reply Last reply Reply Quote 0
                • cvp
                  cvp last edited by

                  But how do you want to specify which you want to remove?

                  1 Reply Last reply Reply Quote 0
                  • RocketBlaster05
                    RocketBlaster05 @cvp last edited by

                    @cvp with my code, I have 11 pins that spawn off startup. I wish to make it so that you can add a dropped pin, then if you do it again it removes the old one. Sorry on this 3 minute timer.

                    cvp 2 Replies Last reply Reply Quote 0
                    • cvp
                      cvp @RocketBlaster05 last edited by

                      @RocketBlaster05 sorry, but I don't understand.
                      At each long press, you want to add a new pin
                      Thus, how to specify that you want to remove a pin?

                      RocketBlaster05 1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @RocketBlaster05 last edited by

                        @RocketBlaster05 with this, no remove

                        def long_press_action(sender):
                        	# Add a pin when the MapView recognizes a long-press
                        	c = sender.point_to_coordinate(sender.long_press_location)
                        	# this of only to special process asked in forum
                        	# https://forum.omz-software.com/topic/7077/removing-custom-pins-with-map-api
                        	if 1==0:#len(sender.mk_map_view.annotations()) == 1:
                        		sender.remove_all_pins()
                        	else:
                        		sender.add_pin(c[0], c[1], 'Dropped Pin', str(c), select=True)
                        	sender.set_center_coordinate(c[0], c[1], animated=True)
                        
                        1 Reply Last reply Reply Quote 0
                        • RocketBlaster05
                          RocketBlaster05 @cvp last edited by

                          @cvp Yes I want to add and remove "Dropped Pin"s only

                          cvp 1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @RocketBlaster05 last edited by

                            @RocketBlaster05 thus a long press adds an additional pin.
                            Which gesture should remove the last one?

                            RocketBlaster05 1 Reply Last reply Reply Quote 0
                            • RocketBlaster05
                              RocketBlaster05 @cvp last edited by

                              @cvp whenever a new pin is added, the only pins that should be removed are any pins named "Dropped Pin." It gets removed once a new pin is added.

                              cvp 1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @RocketBlaster05 last edited by

                                @RocketBlaster05 I think that I'm not very skilled in English but I don't understnd.
                                In this script, all pins are named "dropped", except the first one.

                                RocketBlaster05 1 Reply Last reply Reply Quote 0
                                • RocketBlaster05
                                  RocketBlaster05 @cvp last edited by RocketBlaster05

                                  @cvp yes what you wrote below is correct

                                  1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp last edited by cvp

                                    I think that I begin to understand.
                                    Your code has placed 11 pins and you want that a long press only deletes the pin named dropped.
                                    Is that correct?

                                    RocketBlaster05 1 Reply Last reply Reply Quote 0
                                    • RocketBlaster05
                                      RocketBlaster05 @cvp last edited by

                                      @cvp yes that is correct

                                      cvp 1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @RocketBlaster05 last edited by cvp

                                        @RocketBlaster05 sorry for the misunderstanding

                                        def long_press_action(sender):
                                        	# Add a pin when the MapView recognizes a long-press
                                        	c = sender.point_to_coordinate(sender.long_press_location)
                                        	# this of only to special process asked in forum
                                        	# https://forum.omz-software.com/topic/7077/removing-custom-pins-with-map-api
                                        	for annotation in sender.mk_map_view.annotations():
                                        		if str(annotation.title()) == 'Dropped Pin':
                                        			sender.mk_map_view.removeAnnotation_(annotation)
                                        	else:
                                        		sender.add_pin(c[0], c[1], 'Dropped Pin', str(c), select=True)
                                        	sender.set_center_coordinate(c[0], c[1], animated=True)
                                        
                                        RocketBlaster05 1 Reply Last reply Reply Quote 0
                                        • RocketBlaster05
                                          RocketBlaster05 @cvp last edited by

                                          @cvp works like a charm!

                                          cvp 1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @RocketBlaster05 last edited by

                                            @RocketBlaster05 ouf. Sorry to have been so slow to understand

                                            RocketBlaster05 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors