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.


    Map API, need suggestions for how to execute ideas

    Pythonista
    4
    196
    69693
    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 @cvp last edited by

      @cvp yes! that would be very helpful. I am very thankful you are willing to help out!

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

        @RocketBlaster05

        def compute_region_param(l):
        	# Compute min and max of latitude and longitude
        	min_lat = min(l,key = lambda x:x[0])[0]
        	max_lat = max(l,key = lambda x:x[0])[0]
        	min_lon = min(l,key = lambda x:x[1])[1]
        	max_lon = max(l,key = lambda x:x[1])[1]
        	d_lat = 1.2*(max_lat-min_lat)
        	d_lon = 1.2*(max_lon-min_lon)
        	return min_lat,min_lon,max_lat,max_lon,d_lat,d_lon
        
        def main():
        	.
        	.
        	.
        	# center on user location				
        	import location
        	location.start_updates()
        	time.sleep(1)
        	loc = location.get_location()
        	location.stop_updates()
        	if loc:
        		lat, lon = loc['latitude'], loc['longitude']
        		if locs:
        			min_lat,min_lon,max_lat,max_lon,d_lat,d_lon = compute_region_param(locs)
        			v.set_region((min_lat+max_lat)/2, (min_lon+max_lon)/2,1.2*(max_lat-min_lat), 1.2*(max_lon-min_lon), animated=True)	
        		else:
        			v.set_region(lat, lon, 0.05, 0.05, animated=True)
        
        
        RocketBlaster05 1 Reply Last reply Reply Quote 0
        • RocketBlaster05
          RocketBlaster05 @cvp last edited by

          @cvp this is very good. One more thing for now: I want to make the user's location the purple pin instead of the green/red so that it stands out. I have the location as 'Current Location' for the pin. Any ideas? Thanks

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

            @RocketBlaster05 said:

            user's location the purple pin

            Be careful: if you change something in the mapView_viewForAnnotation_ def, you need to restart Pythonista because the class is already built and kept in memory (restart means remove it from the tasks list and relaunch it)

            Did you remark that if you tap on a pin, you get its title and location.

            Édit: try to avoid to have in the .loc file a point with the same coordinates as the user location,
            because you could have a purple and a green pin at exactly same position and only see one, even with a big zoom.

            def mapView_viewForAnnotation_(self,cmd,mk_mapview,mk_annotation):
            	.
            	.
            	.
            				if tit == 'Dropped Pin':
            					pinView.pinColor = 0 # 0=red 1=green 2=purple
            				elif tit == 'Current Location':
            					pinView.pinColor = 2 # 0=red 1=green 2=purple
            				else:
            					pinView.pinColor = 1 # 0=red 1=green 2=purple
            .
            .
            .
            	loc = location.get_location()
            	location.stop_updates()
            	if loc:
            		lat, lon = loc['latitude'], loc['longitude']
            		# add a purple pin for user's location
            		v.add_pin(lat, lon, 'Current Location', str((lat, lon)))
            		# don't save it in file but add it in locs for centering zoom
            		locs.append((lat,lon))
            		if locs:
            			min_lat,min_lon,max_lat,max_lon,d_lat,d_lon = compute_region_param(locs)
            			v.set_region((min_lat+max_lat)/2, (min_lon+max_lon)/2,1.2*(max_lat-min_lat), 1.2*(max_lon-min_lon), animated=True)	
            		else:
            			v.set_region(lat, lon, 0.05, 0.05, animated=True)
            
            
            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              pin_colors = {
                  "Dropped Pin": 0,  # red
                  "Current Location": 2,  # purple
              }
              …
              pin_color = pin_colors.get(title, 1)  # default to green
              
              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @ccc last edited by cvp

                @ccc said:

                pin_color = pin_colors.get(title, 1) # default to green

                pinView.pin_color = pin_colors.get(tit, 1)  # default to green
                
                1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @RocketBlaster05 last edited by

                  @RocketBlaster05 and tell me if you want to see your own photo instead of a purple pin

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

                    @RocketBlaster05 or, if you prefer,

                    Or, with with some drops of blood 😂

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

                      @RocketBlaster05 and if you want to be able to set view type (satellite, flyover...), you can find this here

                      See two buttons above right of the map

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

                        @cvp said:

                        @RocketBlaster05 and tell me if you want to see your own photo instead of a purple pin

                        This is a great idea. I would like to incorporate this to make the map feel more personal. This may be a big request but can you also show me how to go about making the map start automatically instead of having to press the button? I would like to make it so the button will mark somebody’s location with an image of like a trash bag. Also, is there a simple command I can use to make the map update somebody’s position? I haven’t tried moving around with the map open so if it already moves automatically then that’s my bad for not checking. Thanks in advance.

                        I would like for it to show the face on a little pin, like you showed with the blood. I would like for the memoji to be able to have the trash bag I mentioned before just below it like the blood drop. If that is possible, that would be exactly what I need for my pins.

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

                          An image of like a trash bag… 🚮🗑♻️☠️🤢💰💩🤮

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

                            @RocketBlaster05

                            First of all, as we live in different time zones, dialog is not easy and thus there will be a delay, sometimes big, between questions and answers, in both directions.
                            Secondly, as the script becomes bigger and bigger, I had put it in Github, are you used to download it from Github or do you prefer that I always paste it in the forum topic. If a modification is little, I can paste the modified part only, but if it is long, or in different parts of the script, I would need to paste the entire script every time...
                            Your last post contains several requests, thus I have several questions, could you, please, answer to each of them. I number them so you can only answer by 'n°:answer'.

                            1. do you want the two buttons 3D and MapType and their process?
                            2. do you want a photo/emoji instead of the purple pin of your own location?
                            3. map will be visible automatically if you remove the line "v.hidden = True" in the main.
                            4. replace the map button by another icon and process is easy but I need to know exactly which process. The only problem is to identify which pin...

                            This is how I've modified the script in Github, please try it:

                            • no more map button
                            • no trash button, but:
                              • when you tap on a pin, you see a trash button
                              • if you tap it, the green pin is replaced by a trash on a little pin
                                But the file would not be modified, thus, at next run, you would see your pin's back.
                                Perhaps should be better to entirely remove the location without any trash pin but it is your script thus you have to decide the process you want.

                            Where to tap to delete

                            Result

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

                              @ccc said:

                              An image of like a trash bag… 🚮🗑♻️☠️🤢💰💩🤮

                              Why does💰represent trash? I agree to get your trashes 😂

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

                                @cvp github or the forum here is fine. Whatever is easier for you. The github example you provided is excellent.

                                1. Yes, the map type buttons have some helpful implications and I like having it as an option in the program.
                                2. Yes, I want the emoji instead of the purple pin as it is makes more sense for the user.
                                3. I love that the map opens on its own
                                4. Yes. I want the button to make it so that when the user presses it, it will present a ui.load_view(). From there, the ui.load_view() will ask if the user wants to mark their location with trash (where they are currently located). If they say yes, their location will be marked with the trash symbol. I would like to make it so that if the user marks their location with a trash symbol, that location will be saved onto the loc file for the next time the map is opened.

                                P.S. does the map update the user's position automatically or do I need to input code to make that occur?

                                Thanks so much!

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

                                  @RocketBlaster05 said:

                                  does the map update the user's position automatically or do I need to input code to make that occur?

                                  I don't understand that.
                                  But first, did you try the way I set as trash.
                                  If you have général button to ask something to the user, you would need to also choose the pin.
                                  Anyway, do you need that I do something more?

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

                                    @RocketBlaster05 said:

                                    I would like to make it so that if the user marks their location with a trash symbol, that location will be saved onto the loc file for the next time the map is opened.

                                    It should be possible, when you set a location as trash, to add a line in the file with this location and a flag "trash".
                                    And when you start the script, it checks for ea h location if it is trashed and set a trash pin.
                                    Do you want I program that?

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

                                      @cvp For example, if somebody were to drive for about a mile with the map open, will their marker move with them or does it stay still?

                                      And yes, I used the trash icons. I would like that process to be applied to the user's location through the button I mentioned earlier. However, to make it more simple maybe, could it just drop another pin on the person's location?
                                      For example: The person's emoji is moving across the map, and then they mark their location with the unique trash pin. Their emoji will not get replaced by the trash pin but will just give it a location to be dropped on. Please tell me if I need to explain anything better.

                                      Thanks!

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

                                        @cvp said:

                                        It should be possible, when you set a location as trash, to add a line in the file with this location and a flag "trash".
                                        And when you start the script, it checks for ea h location if it is trashed and set a trash pin.
                                        Do you want I program that?

                                        Yes, that is exactly what I am looking for.

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

                                          @RocketBlaster05 said:

                                          if somebody were to drive for about a mile with the map open, will their marker move with them or does it stay still?

                                          No, pin's location do not move. In the file, their last,Lon are saved and used as is

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

                                            @RocketBlaster05 said:

                                            Yes, that is exactly what I am looking for.

                                            This is done, GitHub updated, try it: set a pin as trash, rerun script and see

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