我有经度和经度,我想打开我的地图应用程序.我从这里试过这段代码.
func goToMap(){
var lat1 : NSString = self.venueLat
var lng1 : NSString = self.venueLng
var latitude:CLLocationDegrees = lat1.doubleValue
var longitude:CLLocationDegrees = lng1.doubleValue
var coordinate = CLLocationCoordinate2DMake(latitude, longitude)
var placemark : MKPlacemark = MKPlacemark(coordinate: coordinate, addressDictionary:nil)
var mapItem:MKMapItem = MKMapItem(placemark: placemark)
mapItem.name = "Target location"
let launchOptions:NSDictionary = NSDictionary(object: MKLaunchOptionsDirectionsModeDriving, forKey: MKLaunchOptionsDirectionsModeKey)
var currentLocationMapItem:MKMapItem = MKMapItem.mapItemForCurrentLocation()
MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions)
}
Run Code Online (Sandbox Code Playgroud)
此功能可以成功打开地图,但不会显示任何图钉.它还显示了我不想要的用户位置.我只想在地图上找到所提供纬度和经度的图钉.
我有一个从Google Places API获得的地方ID,其目的是通过地址ID打开Google地图应用,如下面的类似方法
Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", lat, lon));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
Run Code Online (Sandbox Code Playgroud)
有办法吗?
当用户输入例如来自地方API的"艾菲尔铁塔"时,我已经具有纬度,经度.我将这些值存储在下一个用法中(假设我们列出了一些来自本地数据库的访问位置,用户点击其中一个,app导航到Google Maps)
我有一些担忧
如果我使用纬度 - 经度在Google地图上指示地点而不是地点ID,那么如果"Cafe XYZ"移动到另一条街道会发生什么?
如果我每次使用地方ID来接收"Cafe XYZ"的最后位置(而不是我本地数据库中存储的值),该应用程序很容易达到请求限制
所以这些问题让我想到了一种只发送地点ID Google Maps的方式(比如发送坐标)