Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fit a certain bounds consisting of NE and SW coordinates into the visible map view?
    primarykey
    data
    text
    <p>I need to fit a certain bounds within a map. I get the bounds from calling the google geocoder and reading the viewport property which looks like:</p> <pre><code>{ northeast = { lat = "30.4212235"; lng = "-97.486942"; }; southwest = { lat = "30.1128403"; lng = "-97.99917959999999"; }; } </code></pre> <p>I then convert these into CLLocationCoordinate2D</p> <pre><code>NSDictionary *viewport = [[[results objectAtIndex:0] objectForKey:@"geometry"] objectForKey:@"viewport"]; NSDictionary *NEDictionary = [viewport objectForKey:@"northeast"]; NSDictionary *SWDictionary = [viewport objectForKey:@"southwest"]; CLLocationCoordinate2D SWCoordinate = CLLocationCoordinate2DMake( [[SWDictionary objectForKey:@"lat"] floatValue], [[SWDictionary objectForKey:@"lng"] floatValue] ); CLLocationCoordinate2D NECoordinate = CLLocationCoordinate2DMake( [[NEDictionary objectForKey:@"lat"] floatValue], [[NEDictionary objectForKey:@"lng"] floatValue] ); </code></pre> <p>I know I need to generate a MKMapRect (or MKMapRegion, whichever is easier) from these coordinates and then [mapView setVisibleRect:newRect animated:YES] (or [mapView setRegion:newRegion animated:YES] but I'm not quite sure how to get there. I need a method to convert the bounds into the proper data structure, something like:</p> <pre><code>- (MKMapRect) mapRectThatFitsBoundsSW:(CLLocationCoordinate2D)sw NE:(CLLocationCoordinate2D)ne { // CGFloat x = ?? // CGFloat y = ?? // CGFloat width = ?? // CGFloat height = ?? MKMapRect mapRectFromBounds = MKMapRectMake(x,y,width,height); return mapRectFromBounds; } </code></pre> <p>Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload