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
-
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!
-
@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)
-
Once again you are correct! Thanks once again!
-
@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!
-
@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?
-
@cvp yes.
-
But how do you want to specify which you want to remove?
-
@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.
-
@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 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)
-
@cvp Yes I want to add and remove "Dropped Pin"s only
-
@RocketBlaster05 thus a long press adds an additional pin.
Which gesture should remove the last one? -
@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.
-
@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. -
@cvp yes what you wrote below is correct
-
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? -
@cvp yes that is correct
-
@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)
-
@cvp works like a charm!
-
@RocketBlaster05 ouf. Sorry to have been so slow to understand