귀하의 코드가 잘 보인다. 나는 당신의 문제가 무엇이든, 당신이 게시 한 코드가 아닌 다른 곳에서 왔음을 확신합니다.
또 다른 잠재적 인 문제는지도에서 순환 게재가 허용되는 경우 모든 방향에서 문제가 발생하는 경우 GMSVisibleRegion
개체에 발생한다는 것입니다. (즉, farLeft
속성은 북서쪽 지점과 일치하지 않습니다). 나는 GMSCoordinateBounds
가 그것으로 생각할 것이고 그것에 의해 걸리지 않을 것이라고 생각할 것입니다.
그렇다면 마커의 좌표가 지역에 포함되어 있는지 확인하기위한 고유 한 방법을 쓸 수 있습니다. 대신이 방법을 사용하는 경우
-(BOOL)isMarker:(SGMarker*)m inVisibleRegion:(SGRegion*)region
{
CLLocationCoordinate2D upperLeftPosition = region.topLeft;
CLLocationCoordinate2D lowerRightPosition = region.bottomRight;
if (m.position.latitude > lowerRightPosition.latitude && m.position.latitude < upperLeftPosition.latitude &&
m.position.longitude < lowerRightPosition.longitude && m.position.longitude > upperLeftPosition.longitude) {
return YES;
}
return NO;
}
// In my region wrapper, this is how I make sure I have the north-east/south-west points
+(SGRegion*)regionWithGMSVisibleRegion:(GMSVisibleRegion)region
{
SGRegion* mapRegion = [[self alloc] init];
// Since the camera can rotate, first we need to find the upper left and lower right positions of the
// visible region, which may not correspond to the farLeft and nearRight points in GMSVisibleRegion.
double latitudes[] = {region.farLeft.latitude, region.farRight.latitude, region.nearLeft.latitude};
double longitudes[] = {region.nearRight.longitude, region.nearLeft.longitude, region.farLeft.longitude};
double highestLatitude = latitudes[0], lowestLatitude = latitudes[0];
double highestLongitude = longitudes[0], lowestLongitude = longitudes[0];
for (int i = 1; i < 3; i++) {
if (latitudes[i] >= highestLatitude)
highestLatitude = latitudes[i];
if (latitudes[i] < lowestLatitude)
lowestLatitude = latitudes[i];
if (longitudes[i] >= highestLongitude)
highestLongitude = longitudes[i];
if (longitudes[i] < lowestLongitude)
lowestLongitude = longitudes[i];
}
mapRegion.topLeft = CLLocationCoordinate2DMake(highestLatitude, lowestLongitude);
mapRegion.bottomRight = CLLocationCoordinate2DMake(lowestLatitude, highestLongitude);
return mapRegion;
}
그래서, 당신이 절대적으로 문제가 어디에서 오는 말할 수 있어야한다 (이은 (지역 및 마커에 대한 내 자신의 "래퍼"포함) 내가 작성한 하나입니다 즉 여기에서가 아니라).
줄 3. 불필요한 alloc/init 거기서 - 결코 읽을 수 없습니다 –
마커 배열이 괜찮습니까? 뿐만 아니라 테이블 :) 코드가 괜찮아 보이는 –
전화 시간에 투영 올바른가요? –