【问题标题】:How to integrate Google Map in Objective c?如何在 Objective c 中集成谷歌地图?
【发布时间】:2016-01-17 05:00:02
【问题描述】:

我是 iOS 新手,必须向 Google 地图展示在洛杉矶地区有两个不同纬度和经度的餐厅位置。我需要确保如果用户点击地图,它将允许用户获取前往该特定餐厅的路线。因此,如果所有位置都在一张地图上,用户将需要在地图上单击所需的餐厅/图钉并获取路线 - 对吗?

【问题讨论】:

    标签: ios dictionary sdk


    【解决方案1】:

    试试这个我之前找到的

        In -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker// This method will get call after taping marker pin(GMSMapView map view delegate method).
    { get the latitude and longitude of that marker.
    
    }
    
    Take the latitude and longitude of current location
    
    Now Draw route between two location
    //Download LRouteController from this link  https://github.com/lukagabric/LRouteController
    
    //This will draw link between two co-ordinate
    //In .h File declare LRouteController *_routeController;
     if ([_coordinates count] > 1)
        {
            //Draw line between two co-ordinate
            [_routeController getPolylineWithLocations:_coordinates travelMode:TravelModeDriving andCompletitionBlock:^(GMSPolyline *polyline, NSError *error) {
                if (error)
                {
                    NSLog(@"%@", error);
                }
                else if (!polyline)
                {
                    NSLog(@"No route");
                    [_coordinates removeAllObjects];
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No route" message:@"No route available for this route." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                    [alert show];
                }
                else
                {
                    //Drow route
                    _markerStart.position = [[_coordinates objectAtIndex:0] coordinate];
                    _markerStart.map = googleMapview;
    
                    _markerFinish.position = [[_coordinates lastObject] coordinate];
                    _markerFinish.map = googleMapview;
    
                    _polyline = polyline;
                    _polyline.strokeWidth = 3;
                    _polyline.strokeColor = [UIColor blueColor];
                    _polyline.map = googleMapview;
                }
            }];
        }
    
    
    //If you are unable to get taped pin latitude and longitude the you can use custom GMSMarker
    Ex: @interface MapMarker : GMSMarker //Create new file of GMSMarker
    @property (nonatomic, strong) coOrdinateData *data;(CoOrdinateData is NSObject class declare lat and long value)
    @end
    
    While adding marker on map use 
     MapMarker *marker= [[MapMarker alloc]init];
    
                [marker setPosition:CLLocationCoordinate2DMake(LocationAtual.coordinate.latitude,LocationAtual.coordinate.longitude)];
      marker.data=data;//Take lat and long value in object class and pass object class in marker object
    After typing on map marker you can get value like
    -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
    {
    NSString *strLat = ((MapMarker *)marker).data.lat ;
    NSString *strLong = ((MapMarker *)marker).data.long ;
    //Add both the current location and marker  latitude and longitude in _coordinates and draw route.
    }
    

    【讨论】:

    • 如果您想要添加谷歌地图的步骤,请查看developers.google.com/maps/documentation/ios-sdk/?hl=en
    • 我要先谢谢你。我只需要展示地点 1.Los Angeles,CA 900362 2.Sherman Okas,CA 91403
    • GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:34.08 longitude:-118.336545 zoom:6]; _mapView = [GMSMapView mapWithFrame:_mapView.frame camera:camera]; _mapView.myLocationEnabled = 是; self.view = _mapView; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(34.083811, -118.336545);标记.title = @"";标记.sn-p = @" ";标记.map = _mapView; ;
    • @RakeshBiswal:请将该代码编辑到您的问题中 - 它在 cmets 中几乎不可读。
    猜你喜欢
    • 2012-10-26
    • 2017-11-21
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多