如何在谷歌地图iOS上显示IndoorAtlas的平面图-objective c
我需要将Indoratalas与GMSMapView集成 我在GMSGroundOverlay上显示了平面布置图,但其边界不正确 我正在iOS中搜索等价的地面覆盖选项如何在谷歌地图iOS上显示IndoorAtlas的平面图-objective c,ios,objective-c,google-maps,Ios,Objective C,Google Maps,我需要将Indoratalas与GMSMapView集成 我在GMSGroundOverlay上显示了平面布置图,但其边界不正确 我正在iOS中搜索等价的地面覆盖选项 BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); IALatLng iaLatLng = floorPlan.getCenter(); LatLng center = new LatLng(iaLatLng.latitud
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
IALatLng iaLatLng = floorPlan.getCenter();
LatLng center = new LatLng(iaLatLng.latitude, iaLatLng.longitude);
GroundOverlayOptions fpOverlay = new GroundOverlayOptions()
.image(bitmapDescriptor)
.position(center, floorPlan.getWidthMeters(), floorPlan.getHeightMeters())
.bearing(floorPlan.getBearing());
mGroundOverlay = mMap.addGroundOverlay(fpOverlay);
我从这里得到了密码:
欢迎提出任何建议
图标必须位于蓝色三角形内
-(void)changeMapOverlay2{
NSLog(@" ------> changeMapOverlay");
resultLogLabel.text = [NSString stringWithFormat:@"------> changeMapOverlay"];
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:floorPlan.topRight.latitude longitude:floorPlan.topRight.longitude];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:floorPlan.topLeft.latitude longitude:floorPlan.topLeft.longitude];
CLLocation *location3 = [[CLLocation alloc] initWithLatitude:floorPlan.bottomLeft.latitude longitude:floorPlan.bottomLeft.longitude];
CLLocationDistance meters = [location1 distanceFromLocation:location2];
CLLocationCoordinate2D result1 = [self locationWithBearing:degreesToRadians(90) distance:meters fromLocation:location1.coordinate];
NSLog(@"meter %f from : ( %f, %f)", meters ,location1.coordinate.latitude , location1.coordinate.longitude);
meters = [location2 distanceFromLocation:location3];
CLLocationCoordinate2D result2 = [self locationWithBearing:degreesToRadians(0) distance:meters fromLocation:result1];
NSLog(@"meter %f from : ( %f, %f)", meters ,location2.coordinate.latitude , location2.coordinate.longitude);
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(result2.latitude, result2.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.topRight.latitude, floorPlan.topRight.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(result1.latitude, result1.longitude)];
GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithPath:path];
UIImage *icon = fpImage ;
GMSGroundOverlay *overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon];
overlay.bearing = floorPlan.bearing;
overlay.map = map;}
这是我如何用平面布置图的坐标画蓝色三角形的代码
-(void) drawFloorPlan{
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.topLeft.latitude, floorPlan.topLeft.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.topRight.latitude, floorPlan.topRight.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.bottomLeft.latitude, floorPlan.bottomLeft.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.topLeft.latitude, floorPlan.topLeft.longitude)];
[path addCoordinate:CLLocationCoordinate2DMake(floorPlan.center.latitude, floorPlan.center.longitude)];
GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
rectangle.strokeColor = [UIColor blueColor];
rectangle.map = map;
/****************************/
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:floorPlan.topRight.latitude longitude:floorPlan.topRight.longitude];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:floorPlan.topLeft.latitude longitude:floorPlan.topLeft.longitude];
CLLocation *location3 = [[CLLocation alloc] initWithLatitude:floorPlan.bottomLeft.latitude longitude:floorPlan.bottomLeft.longitude];
CLLocationDistance meters = [location1 distanceFromLocation:location2];
CLLocationCoordinate2D result1 = [self locationWithBearing:degreesToRadians(90) distance:meters fromLocation:location1.coordinate];
meters = [location2 distanceFromLocation:location3];
CLLocationCoordinate2D result2 = [self locationWithBearing:degreesToRadians(0) distance:meters fromLocation:result1];
GMSMutablePath *path2 = [GMSMutablePath path];
[path2 addCoordinate:CLLocationCoordinate2DMake(floorPlan.topRight.latitude, floorPlan.topRight.longitude)];
[path2 addCoordinate:CLLocationCoordinate2DMake(result1.latitude, result1.longitude)];
[path2 addCoordinate:CLLocationCoordinate2DMake(result2.latitude, result2.longitude)];
GMSPolyline *line = [GMSPolyline polylineWithPath:path2];
line.strokeColor = [UIColor redColor];
line.map = map;}
我找到了解决办法。
对于每个想在谷歌地图上显示IndoorAtlas的平面图的人,下面是代码。
这是计算坐标的函数
-(NSArray *)calculateLongLatDegreesInMeters:(CLLocationDegrees)latitude {
float lat = M_PI * latitude / 180;
// Constants for calculating lengths
float m1 = 111132.92;
float m2 = -559.82;
float m3 = 1.175;
float m4 = -0.0023;
float p1 = 111412.84;
float p2 = -93.5;
float p3 = 0.118;
float eq1 = m1 + (m2 * cos(2 * lat)) + (m3 * cos(4 * lat));
float latitudeDegreeInMeters = eq1 + (m4 * cos(6 * lat));
float longitudeDegreeInMeters = (p1 * cos(lat)) + (p2 * cos(3 * lat)) + (p3 * cos(5 * lat));
NSString *latDegInMtr = [NSString stringWithFormat:@"%f",latitudeDegreeInMeters];
NSString *lonDegInMtr = [NSString stringWithFormat:@"%f",longitudeDegreeInMeters];
NSArray *arr = [NSArray arrayWithObjects:latDegInMtr,lonDegInMtr, nil];
return arr; //(latitudeDegreeInMeters, longitudeDegreeInMeters)}
这是谷歌地图上显示平面图的功能
-(void) setGroundOverlay {
overlay2.map = nil;
CLLocationCoordinate2D center = floorPlan.center ;
float pixelsToMeters = floorPlan.pixelToMeterConversion;
float heightForCoordinates = floorPlan.height/2 ;
float widthForCoordinates = floorPlan.width/2;
float metersHorizontal = widthForCoordinates * pixelsToMeters;
float metersVertical = heightForCoordinates * pixelsToMeters;
NSArray *lengths = [self calculateLongLatDegreesInMeters:center.latitude];
double longitudes = (double)metersHorizontal / [[lengths objectAtIndex:1] doubleValue];
double latitudes = (double)metersVertical / [[lengths objectAtIndex:0] doubleValue];
CLLocationCoordinate2D southWestCoordinates = CLLocationCoordinate2DMake(center.latitude - latitudes, center.longitude - longitudes);
CLLocationCoordinate2D northEastCoordinates = CLLocationCoordinate2DMake(center.latitude + latitudes, center.longitude + longitudes);
GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWestCoordinates coordinate:northEastCoordinates];
// Resize the floorplans so that they work with Google Maps SDK GMSGroundOverlay
UIImage *icon = [self imageWithImage:fpImage scaledToSize:CGSizeMake(4000, 4000)];
overlay2 = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon];
overlay2.bearing = floorPlan.bearing;
overlay2.map = map;}
这是最后一个调整楼层平面图像大小的函数
-(UIImage*)imageWithImage:(UIImage*)oldImage scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[oldImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;}
我找到了解决办法。
对于每个想在谷歌地图上显示IndoorAtlas的平面图的人,下面是代码。
这是计算坐标的函数
-(NSArray *)calculateLongLatDegreesInMeters:(CLLocationDegrees)latitude {
float lat = M_PI * latitude / 180;
// Constants for calculating lengths
float m1 = 111132.92;
float m2 = -559.82;
float m3 = 1.175;
float m4 = -0.0023;
float p1 = 111412.84;
float p2 = -93.5;
float p3 = 0.118;
float eq1 = m1 + (m2 * cos(2 * lat)) + (m3 * cos(4 * lat));
float latitudeDegreeInMeters = eq1 + (m4 * cos(6 * lat));
float longitudeDegreeInMeters = (p1 * cos(lat)) + (p2 * cos(3 * lat)) + (p3 * cos(5 * lat));
NSString *latDegInMtr = [NSString stringWithFormat:@"%f",latitudeDegreeInMeters];
NSString *lonDegInMtr = [NSString stringWithFormat:@"%f",longitudeDegreeInMeters];
NSArray *arr = [NSArray arrayWithObjects:latDegInMtr,lonDegInMtr, nil];
return arr; //(latitudeDegreeInMeters, longitudeDegreeInMeters)}
这是谷歌地图上显示平面图的功能
-(void) setGroundOverlay {
overlay2.map = nil;
CLLocationCoordinate2D center = floorPlan.center ;
float pixelsToMeters = floorPlan.pixelToMeterConversion;
float heightForCoordinates = floorPlan.height/2 ;
float widthForCoordinates = floorPlan.width/2;
float metersHorizontal = widthForCoordinates * pixelsToMeters;
float metersVertical = heightForCoordinates * pixelsToMeters;
NSArray *lengths = [self calculateLongLatDegreesInMeters:center.latitude];
double longitudes = (double)metersHorizontal / [[lengths objectAtIndex:1] doubleValue];
double latitudes = (double)metersVertical / [[lengths objectAtIndex:0] doubleValue];
CLLocationCoordinate2D southWestCoordinates = CLLocationCoordinate2DMake(center.latitude - latitudes, center.longitude - longitudes);
CLLocationCoordinate2D northEastCoordinates = CLLocationCoordinate2DMake(center.latitude + latitudes, center.longitude + longitudes);
GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWestCoordinates coordinate:northEastCoordinates];
// Resize the floorplans so that they work with Google Maps SDK GMSGroundOverlay
UIImage *icon = [self imageWithImage:fpImage scaledToSize:CGSizeMake(4000, 4000)];
overlay2 = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon];
overlay2.bearing = floorPlan.bearing;
overlay2.map = map;}
这是最后一个调整楼层平面图像大小的函数
-(UIImage*)imageWithImage:(UIImage*)oldImage scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[oldImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;}
您最好向他们的在线支持人员询问。@CeneCode我问了,但我仍在等待答复,告诉我们您做了什么;)代码——以及一个正方形如何与一个三角形相匹配?@Daij Djan蓝色三角形是平面图的右坐标。我使用它作为GMSGroundOverlay的边界,但图标在三角形之外。你最好向他们的在线支持人员询问这个问题。@CeneCode我问过了,但我仍在等待回答,告诉我们你有什么完成;)代码——以及一个正方形如何适合一个三角形?@Daij Djan蓝色三角形是平面图的右坐标。我使用它作为GMSGroundOverlay的边界,但图标在三角形之外