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
-
@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
-
@cvp school's been rough lately lol. Teacher is asking I make more modifications to the map we were talking about so that I can collect some data... I have a simple ui.load_view() I plan to make later which will ask the user if they want to mark their current location on the map. However I would need a button to be pressed for the user to get the view to work. Also, the user would need to be able to do so as many times as they like, so that multiple marks can appear on the map. The positions of the markers would need to be saved so that the next time the map is activated, the markers will reappear. I understand this is likely a fair amount of code, but any help would be greatly appreciated. I will not be able to test the code for a few hours because my iPad is at home and I am at school. If you could suggest any ideas for me to test later I would be very thankful.