如何处理导航方向?
/**
* 设备旋转方向事件回调。结合地图方向模式TYMapViewModeFollowing可以处理地图自动旋转,
以及方向箭头随地磁旋转功能。
*
* @param manager 定位引擎实例
* @param newHeading 新的设备方向结果
*/- (void)TYLocationManager:(TYLocationManager *)manager didUpdateDeviceHeading:
(double)newHeading {
NSLog(@"地图初始北偏角:%f,当前设备北偏角:%f",self.mapView.building.
initAngle,newHeading);
//初始北偏角内部已经处理
[self.mapView processDeviceRotation:newHeading];}
2. 如何计算导航距离?
double len = 0;
for (TYRoutePart *rp in routeResult.allRoutePartArray) {
len += [[AGSGeometryEngine defaultGeometryEngine] distanceFromGeometry:rp.
getFirstPoint toGeometry:rp.getLastPoint];
}
int min = ceil(len/80);
[self textToSpeech:
[NSString stringWithFormat:@"开始导航,全程%.0f米,大约需要%d分钟",len,min]];
3. 如何获取导航提示?
TYRoutePart *part = [routeResult getNearestRoutePart:localPoint];
//导航提示
NSArray *routeGuides = [routeResult getRouteDirectionalHint:part];
if (routeGuides.count) {
TYDirectionalHint *hint =
[routeResult getDirectionHintForLocation:localPoint FromHints:routeGuides];
[self textToSpeech:[hint getDirectionString]];
}
4. 导航语音怎么集成?
直接使用IOS自带AVSpeechSynthesizer即可实现:
- (IBAction)textToSpeech:(NSString *)text
{
[self.speech stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:text];
//需要转换的文本
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
float sysVer = [UIDevice currentDevice].systemVersion.floatValue;
if (sysVer < 9) {
utterance.rate = 0.15;
}else if(sysVer == 9){
utterance.rate = 0.53;
}else{
utterance.rate = 0.5;
}
// utterance.pitchMultiplier = 2;
[self.speech speakUtterance:utterance];
}