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.


    Getting "region" in MKMapView

    Pythonista
    2
    3
    1354
    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.
    • becktrex
      becktrex last edited by

      I am working on a project using a MapView based on @jsbain "Map View Demo2.py" jsbain github

      I am adding a set of anotations that I getting from Open Street Maps (OSM) and that requires that I first limit to a geographical range.
      In order to do that, I need to know that lat/long range of the display.

      'get_center_coordinate()' works great for "where" I am but to get limit the range I need to know the "span" of the mapview.
      I thought that it would be easy to just copy the code from get_center_coordinate() to create get_region() (see below) but my code causes an error; "No method found for region"

      The Apple documentation MKMapView shows that 'centerCoordinate' only differs from 'region' in the return type ('CLLocationCoordinate2D' vs 'MKCoordinateRegion'

      My understanding of objective C is poor at best and so is nderstanding of the objc_util module.
      Any help I can get whether it be a hint or actual working code would be appreciated.

      *This method works great

      	def get_center_coordinate(self):
      		"""Return the current center coordinate as a (latitude, longitude) tuple"""
      		coordinate = self.mk_map_view.centerCoordinate(restype=CLLocationCoordinate2D, argtypes=[])
      		return coordinate.latitude, coordinate.longitude
      

      This method errors: "No method found for region"

      	@on_main_thread
      	def get_region(self):
      		"""Return latitude /longitude of the view's center and the zoom level (specified implicitly as a latitude/longitude delta)"""
      		region = self.mk_map_view.region(restyle=MKCoordinateRegion,argtypes=[])
      		return region.center.latitude, region.center.longitude, region.span.d_lat, region.span.d_lon
      

      '''

      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @becktrex last edited by

        @becktrex, it’s probably just the typo, ”restyle”.

        1 Reply Last reply Reply Quote 1
        • becktrex
          becktrex last edited by

          Yep, that was it restyle s/b restype

          The problem with “cut and paste” programming is that I don’t know enough about what I’m seeing to see the obvious. In this case I should have “cut and paste” one more time, and it would have given me no trouble.

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