简体   繁体   English

如何在Google Maps App中从另一个位置显示当前位置?

[英]How to show the current location from another location in google maps App?

I integrated google maps in my app. 我在我的应用程序中集成了谷歌地图。 I have to show map from current location to destination. 我必须显示从当前位置到目的地的地图。 In my app, It's working fine. 在我的应用中,一切正常。 I had taken a subview on the top of map view. 我在地图视图的顶部做了一个子视图。 Inside the view I have a button, If i am clicking on the button. 在视图内部,如果单击按钮,则有一个按钮。 I am navigating to google maps app. 我正在导航到Google Maps应用。 But it's showing only current location. 但它仅显示当前位置。 It's not showing the destination. 它没有显示目的地。

Here is my code... 这是我的代码...

- (IBAction)onMapNavigationButtonClick:(id)sender {
UIApplication *app = [UIApplication sharedApplication];
NSString *anURLString = [NSString stringWithFormat:@"http://maps.google.com/maps?pickupLat=%f&pickupLng=%f&dropLat=%f&dropLng=%f",self.a2bBooking.pickupLocation.latitude,self.a2bBooking.pickupLocation.longitude ,self.selectedDestinationZone.latitude.doubleValue,self.selectedDestinationZone.longitude.doubleValue];
[app openURL:[NSURL URLWithString:anURLString]];
}

If anyone having idea about this.Please help me out.. 如果有人对此有想法,请帮助我。

Thanks.. 谢谢..

Google has a Google Maps URLs API and you can use it to open an app in directions or navigation mode. Google有Google Maps URLs API,您可以使用它在方向或导航模式下打开应用程序。 Have a look at aforementioned documentation for further details. 请查看上述文档以获取更多详细信息。

Your code should be changed to something similar to 您的代码应更改为类似于

- (IBAction)onMapNavigationButtonClick:(id)sender {
    UIApplication *app = [UIApplication sharedApplication];
    NSString *anURLString = [NSString stringWithFormat:@"https://www.google.com/maps/dir/?api=1&origin=%f,%f&destination=%f,%f&travelmode=driving",self.a2bBooking.pickupLocation.latitude,self.a2bBooking.pickupLocation.longitude ,self.selectedDestinationZone.latitude.doubleValue,self.selectedDestinationZone.longitude.doubleValue];
    [app openURL:[NSURL URLWithString:anURLString]];
}

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM