構造 Google Maps Web URL,包含標題、經緯度、縮放級別,用 UIApplication.shared.openURL 唤起系統地圖 App(或瀏覽器)。
NSString *title = @"目的地";
float latitude = 35.4634;
float longitude = 9.43425;
int zoom = 13;
NSString *urlString = [NSString stringWithFormat:
@"https://maps.google.com/maps?q=%@@%1.6f,%1.6f&z=%d",
title, latitude, longitude, zoom];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
q=label@lat,lng:標記點標題與坐標。z=zoom:縮放級別 (1-20)。%1.6f 保留 6 位小數(約 0.1 米精度)。NSString *urlString = [NSString stringWithFormat:
@"https://maps.apple.com/?q=%@&ll=%f,%f&z=%d",
title, latitude, longitude, zoom];
// 優先喚起 Apple Maps,無則瀏覽器打開 Google Maps
Info.plist 添加 LSApplicationQueriesSchemes 包含 maps,否則 canOpenURL 返回 false(但 openURL 通常仍可)。[title stringByAddingPercentEncodingWithAllowedCharacters:.URLQueryAllowedCharacterSet]。一行 URL 唤起地圖導航,無需集成複雜 SDK。