2016-06-06 5 views
0

Google Maps nicht den aktuellen Standort vergrößern könnte nach vielen Lösung über Stapel wie Zoom in to current location on map in Objekt c suchen, aber ich fand eine Lösung, mir helfen konnte, aber es war in swift geschrieben Current Location in Google Maps with swiftGoogle Maps vergrößern Zum aktuellen Standort in ios

-Code

.h Datei

#import <UIKit/UIKit.h> 
@import GoogleMaps; 
@interface BranchesViewController : UIViewController <GMSMapViewDelegate,CLLocationManagerDelegate> 

@property (weak, nonatomic) IBOutlet GMSMapView *mapView; 
@property (nonatomic, retain) CLLocationManager *locationManager; 

@end 

.m Datei

// 
// BranchesViewController.m 
// Geeks Diner 
// 
// Created by Zakaria Darwish on 5/15/16. 
// Copyright © 2016 CodeBee. All rights reserved. 
// 

#import "BranchesViewController.h" 
#import "infoWindow.h" 
#import "SplashViewController.h" 
#import "sharedVariables.h" 
#import"AFNetworking.h" 
#import "UIWebView+AFNetworking.h" 
#import "SDWebImageCompat.h" 
#import "SDWebImageDownloaderOperation.h" 
#import "SDWebImageDownloader.h" 
#import "MyGeeksTableViewController.h" 
#import "GeeksLocations.h" 
#import "BranchDetailsViewController.h" 
@import GoogleMaps; 

@interface BranchesViewController() <GMSMapViewDelegate> 

@end 

@implementation BranchesViewController 
{ 
    GMSMarker *marker_1; 
    BOOL firstLocationUpdate_; 
    CLLocationCoordinate2D *startPoint; 
    CLLocation *myLocation; 
    NSMutableArray *list; 


} 



-(void)getCurrentLocationAndZoomToIt { 



} 



//- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
// GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude 
//               longitude:newLocation.coordinate.longitude 
//                 zoom:17.0]; 
// [self.mapView animateToCameraPosition:camera]; 
// CLLocation *location = newLocation; 
// 
// 
// 
// 
// 
//// 
//// let userLocation = locations.last 
//// let center = CLLocationCoordinate2D(latitude: userLocation!.coordinate.latitude, longitude: userLocation!.coordinate.longitude) 
//// 
//// let camera = GMSCameraPosition.cameraWithLatitude(userLocation!.coordinate.latitude, 
////              longitude: userLocation!.coordinate.longitude, zoom: 8) 
//// let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera) 
//// mapView.myLocationEnabled = true 
//// self.view = mapView 
//// 
//// let marker = GMSMarker() 
//// marker.position = center 
//// marker.title = "Current Location" 
//// marker.snippet = "XXX" 
//// marker.map = mapView 
//// 
//// locationManager.stopUpdatingLocation() 
// } 

-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker 
{ 
    NSLog(@"tapped"); 
    // we need to move into new view // 

    BranchDetailsViewController *avc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"branchdetailviewcontroller"]; 
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:avc]; 
    //  nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentViewController:nav animated:YES completion:nil]; 

} 




-(UIImage *)getImage :(UIImage *)icon stop:(NSString *)stopNumber color:(UIColor *)color 
{ 
    // create label 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, icon.size.width,icon.size.height)]; 
    [label setText:stopNumber]; 
    [label setTextColor:color]; 
    [label setFont:[UIFont boldSystemFontOfSize:11]]; 
    label.textAlignment = NSTextAlignmentCenter; 

    //start drawing 
    UIGraphicsBeginImageContext(icon.size); 

    //draw image 
    [icon drawInRect:CGRectMake(0, 0, icon.size.width, icon.size.height)]; 

    //draw label 
    [label drawTextInRect:CGRectMake((icon.size.width - label.frame.size.width)/2, -5, label.frame.size.width, label.frame.size.height)]; 

    //get the final image 
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 
    return resultImage; 
} 




- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.mapView.delegate = self; 

    self.locationManager = [[CLLocationManager alloc] init] ; 
    self.locationManager.delegate = self; 
    [self.locationManager requestWhenInUseAuthorization]; 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation ; 
    [self.locationManager setDistanceFilter:10.0f] ; 
    [self.locationManager startUpdatingLocation]; 

    // UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]]; 
    // // Width equivalent to system default Done button's (which appears on pushed view in my case). 
    // rightBarButtonItem.enabled = NO; 
    // self.navigationItem.leftBarButtonItem = rightBarButtonItem; 
    [self getGeeksLocations]; 



} 


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation 
{ 



    [self.locationManager stopUpdatingLocation]; 
    CLLocationCoordinate2D zoomLocation; 
    // zoomLocation.latitude = self.mapView.myLocation.location.coordinate.latitude; 
    // zoomLocation.longitude= YourMapView.userLocation.location.coordinate.longitude; 
    // 2 
    // MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*1609.344, 0.5*1609.344); 
    // 3 
    // [self.mapView setRegion:viewRegion animated:YES]; 


//  [self.locationManager stopUpdatingLocation]; 
//   zoomLocation.latitude = self.mapView.userLocation.location.coordinate.latitude; 
//  zoomLocation.longitude= self.mapView.userLocation.location.coordinate.longitude; 
//  // 2 
//  MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*1609.344, 0.5*1609.344); 
//  // 3 
//  [self.mapView setRegion:viewRegion animated:YES]; 
} 

so könnte jemand mir helfen mit, dass ??

Antwort

1

Sie können die Karte verschieben oder ihre Perspektive mit sehr geringer Latenz ändern. Peilung, Neigung, Position und zoom level der Karte können über das GMSCameraPosition-Objekt programmgesteuert gesteuert werden.

Sie können -animateToZoom: auf Ihrem GMSMapView verwenden, oder Sie können eine GMSCameraPosition erstellen und die und Zoom-Ebene koordinieren und dann -animateToCameraPosition: verwenden oder eine GMSCameraUpdate erstellen und verwenden Sie dann -animateWithCameraUpdate:

GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithLatitude:latitude 
longitude:longitude 
zoom:11.0]; 

[self.mapView animateToCameraPosition:cameraPosition]; 

oder

GMSCameraUpdate *update = [GMSCameraUpdate zoomTo:11.0]; 
[self.mapView animateWithCameraUpdate:update]; 

oder

[self.mapView animateToZoom:11.0]; 
+0

ich weiß nicht, wie aktuelle Lage und zoomen, um es zu vergrößern zu bekommen? –

3

func Locationmanager (_ Manager: CLLocationManager, didUpdateLocations Orte: [CLLocation]) {

let locValue:CLLocationCoordinate2D = manager.location!.coordinate 
mapView.animate(toLocation: CLLocationCoordinate2D(latitude: locValue.latitude, longitude: locValue.longitude)) 

    mapView.setMinZoom(4.6, maxZoom: 20) 


} 
Verwandte Themen