我有这样的代码:
if(navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPod") != -1 || navigator.platform.indexOf("iPad") != -1) {
window.open("https://maps.google.com?saddr=Current+Location&daddr=" + lat + "," + lon);
}
else {
window.open("https://www.google.com/maps/dir/Current+Location/" + lat + "," + lon);
//window.open("https://maps.google.com?saddr=Current+Location&daddr=" + lat + "," + lon);
}
我知道lon和lat有正确的值。它可以在所有桌面浏览器和我测试过的安卓手机上运行(给我指引),但当我在iphone上运行window.open时,它会加载谷歌地图,并显示“找不到路线”。
这段代码不能在ios设备上运行吗?
发布于 2015-05-21 18:32:36
有两种方法可以将Google Maps URL嵌入到iOS应用程序中。
使用class.
class.
的
在第一个示例中,很容易构建链接来直接在Google Maps for iOS中打开地图(或显示街景或方向)。您可以使用Objective-C类和类型创建地图请求,而不是手动创建URL,这样您就可以利用Xcode所提供的所有类型检查和代码提示。
对于Direction,请遵循以下代码:
GoogleDirectionsDefinition *defn = [[GoogleDirectionsDefinition alloc] init];
defn.startingPoint =
[GoogleDirectionsWaypoint waypointWithQuery:@"221B Baker Street, London"];
defn.destinationPoint = [GoogleDirectionsWaypoint
waypointWithLocation:CLLocationCoordinate2DMake(51.498511, -0.133091)];
defn.travelMode = kGoogleMapsTravelModeBiking;
[[OpenInGoogleMapsController sharedInstance] openDirections:defn];
要启动用于iOS的Google Maps应用程序并可选地执行其中一个受支持的功能,请使用以下形式的URL方案:
comgooglemaps://?parameters
使用显示方向方案请求和显示两个位置之间的方向。您还可以指定运输模式。下面是一个示例URL,用于显示Google NYC和JFK机场之间的交通路线:
comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit
希望tat能帮上忙!
https://stackoverflow.com/questions/30351222
复制相似问题