Groonga with MapKit

Groonga with MapKit

D3c5c0241a5b95751afb89ff2b45429d?s=128

takatomo okitsu

November 29, 2013
Tweet

Transcript

  1. GroongaͱMapKit גࣜձࣾσΟʔɾΤψɾΤʔ ΤϯλʔςΠϝϯτࣄۀຊ෦ ԭ௡ وஐ

  2. ࣗݾ঺հ • ԭ௡وஐ @okitsu • 2011೥10݄ೖࣾɻ • ΤϯλʔςΠϝϯτࣄۀຊ෦ॴଐ • ࠷ۙͷϝΠϯ͸iOS։ൃɻαʔόαΠυ΋ͪΐ͍ͪ

    ΐ͍ɻ https://www.facebook.com/okitsu.takatomo
  3. • Mobage • Comm: Free calls, texts and fun! •

    Baseball Staduim LIVE • Peko: Play to be Paid! ؔΘͬͨϓϩμΫτ Now
  4. ΤϯλʔςΠϝϯτࣄۀຊ෦ͱ͸ʁ • ඇήʔϜͷ৽نࣄۀ։ൃΛ୲౰͢Δ෦ॺ • େখ༷ʑͳαʔϏεɾϓϩμΫτΛ։ൃதɻ • ࠓ೥౓͸̓ຊ΄ͲϦϦʔεࡁΈɻ೥౓຤·Ͱ10ຊҎ্ ? ? ?

  5. ࠓճղઆ͢ΔϓϩμΫτ

  6. ※೔ຊͰ͸ϦϦʔεͯ͠·ͤΜ

  7. None
  8. Ґஔ৘ใʹؔ͢Δ ओͳϢʔεέʔε • ද͍ࣔͯ͠ΔMapͷൣғʹ͍ΔϢʔβΛݕࡧ → Map্ʹϐϯΛཱͯΔ • ࣗ෼͕͍ΔҐஔ͔Β͍ۙॱʹݕࡧ GroongaͰ࣮ݱ

  9. Ґஔ৘ใͷߋ৽ Groonga MySQL JSONRPC Server JSONRPC load (over http) response

    latitude / longtitude save iOSͷLocationAPIͰ Ң౓ܦ౓औಘ
  10. Ґஔ৘ใͷߋ৽ • MySQLʹҢ౓/ܦ౓ΛJSONܗࣜͰ֨ೲ {"lat":"35.440098", "lon":"139.627821"} • ͦͷޙɺGroongaʹloadίϚϯυͰอଘ (httpܦ༝) Ϛελʔσʔλ͸͋͘·Ͱ΋MySQLͰ؅ཧ Groongaͷσʔλ͸ݕࡧઐ༻

    load --table Users [ { "_key": "123", "location": "35.440098x139.627821", } ] ※_key͸ϢʔβID
  11. ※ಛఆͷൣғʹ͍ΔϢʔβͷݕࡧ Groonga MySQL JSONRPC Server JSONRPC ϢʔβҰཡ ӈ্ʢ๺౦ʣͷlatitude / longtitude

    sql ࠨԼʢೆ੢ʣͷlatitude / longtitude + geo_in_circleͰϑΟϧλ Ґஔ৘ใͷݕࡧ ϢʔβҰཡ ϢʔβҰཡ select (over http)
  12. iOSʹ͓͚Δൣғͷಛఆํ๏ CGPoint northEast = CGPointMake( self.mapView.bounds.origin.x+self.mapView.bounds.size.width, self.mapView.bounds.origin.y ); CLLocationCoordinate2D convertNorthEast

    = [self.mapView convertPoint:northEast toCoordinateFromView:self.mapView]; CGPoint southWest =CGPointMake( self.mapView.bounds.origin.x, self.mapView.bounds.origin.y+self.mapView.bounds.size.height ); CLLocationCoordinate2D convertSouthWest = [self.mapView convertPoint:southWest toCoordinateFromView:self.mapview];
  13. αʔόαΠυͰ2఺ͷ࠲ඪΛԁʹม׵ αʔόαΠυͰɺ2఺ͷ࠲ඪ Λԁʹม׵͔ͯ͠Βɺ geo_in_circleؔ਺Λར༻ͯ͠ Groongaʹ໰͍߹Θͤ use Geo::Direction::Distance

  14. ͳͥΘ͟Θ͟ԁࢦఆʹม׵͍ͯ͠Δͷ͔ʁ • Groongaʹ͸geo_in_rectangleͱ͍͏ؔ਺͕͋ΓɺͦΕΛϑΟϧλʔʹ࢖͑ ͹ɺΘ͟Θ͟2఺ͷ࠲ඪ͔Βԁʹม׵ͯ͠ࢦఆ͢Δඞཁ͸ͳ͍ɻ • ౰વɺ࠷ॳ͸ͦ͏΍ͬͯͨΜͰ͕͢ɾɾɾɾ Կճ΍ͬͯ΋ೆ൒ٿͷϢʔβ͕ ώοτ͠ͳ͍ɻ ΦʔετϥϦΞͱ͔ೆถͷਓؒ શһࢮΜͩΜ͡Όͳ͍͔ʂ

  15. ιʔεݟͨ negative coordinate is not implemented!!!

  16. RedmineͰλεΫൃݟ

  17. geo_in_rectangleؔ਺Λ࢖͏৔߹ʹ͸ ͝஫ҙ͍ͩ͘͞ɻ ※೔ຊݶఆͱ͔ͩͱͨͿΜେৎ෉

  18. ϑϦοΫͰMapΛ্ԼࠨӈʹҠಈ ͨ͠ΓɺεϫΠϓͰMapΛ֦େɾ ॖখͨ͠৔߹ɺ৽͍͠ൣғͰϢʔ βΛ࠶औಘ͠ͳ͍ͱ͍͚ͳ͍ MapΛϑϦοΫ/εϫΠϓͯ͠Ҡಈͨ͠৔߹ͷ ߋ৽ํ๏

  19. - (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)animated { [self performSelector:@selector(updateDisplayedRegionUsers) withObject:self afterDelay:2.0]; } -

    (void)mapView:(MKMapView*)mapView regionWillChangeAnimated:(BOOL)animated { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(updateDisplayedRegionUsers) object:nil]; } MapΛϑϦοΫ/εϫΠϓͯ͠Ҡಈͨ͠৔߹ͷ ߋ৽ํ๏ • Ґஔͷมߋ͕ߦΘΕ͔ͯΒɺ2ඵޙʹαʔό͔Β࠶औಘ͢Δɻ • 2ඵҎ಺ʹ࠶౓Ґஔͷมߋ͕ߦΘΕͨΒɺऔಘΛΩϟϯηϧ͢Δɻ
  20. ͨ·ʹGoongaͷ selectͰίέΔ໰୊ • GroongaͱͷΠϯλϑΣʔε͸ɺAnyEvent::GroongaΛ࢖͍͕ͬͯͨɺ ͨ·ʹselectͰίέͰ্ख͘৘ใ͕औಘͰ͖ͳ͍έʔε͕͋ͬͨɻ • ௐ΂ͨͱ͜ΖɺAnyEventΛ࢖ͬͯඇಉظͰhttp઀ଓ͍ͯ͠Δ͋ͨΓ͕ ո͔ͬͨͨ͠ΊɺfurlͰಉظతʹ઀ଓ͢ΔΑ͏ʹஔ͖׵͑ͨɻ → ௒ઈ҆ఆʂ

    ※ݪҼಛఆʹ͸ࢸΒͣɺ͍͢·ͤΜɻɻ AnyEvent::Groonga Λར༻͢Δ৔߹͸͝஫ҙ͍ͩ͘͞ɻ
  21. ඇಉظ→ಉظͩͱύϑΥʔϚϯε͕ ؾʹͳΔ → ϕϯνͱͬͨ API (※1) ϦΫΤετ਺ ฏۉϨεϙϯε λΠϜ(s) εϧʔϓοτ

    (ϦΫΤετ਺/s) updateLocation ʢҐஔ৘ใͷߋ৽ʣ 101892 0.358 s 550.3 searchUserByRegion ʢҐஔ৘ใͷݕࡧʣ 109224 0.380 s 449.7 ※1 JSONRPCαʔόͷAPI໊Ͱ͢ɻ͜ͷAPIͷதͰಉظతʹGroongaΛ͍ͨͨͯ·͢ɻ JSONRPCαʔό୆਺ : 2୆ ʢϋʔυεϖοΫ๨Εͨɻੴڮ͞Μʹ֬ೝ͠·͢ʣ JSONRPCαʔόworker਺ : 200 Groongaαʔό୆਺ : 2୆ ΫϥΠΞϯτଟॏ౓ : ඵؒ200ϦΫΤετ ༨༟Ͱڐ༰ൣғ
  22. ӡ༻ͷ࿩ʢಛʹՄ༻ੑʣ Groonga-1 load Groonga-2 JSONRPC αʔό update location • Groonga͸ϚϧνϚελߏ੒ɻߋ৽͸͢΂ͯͷGroonga

    ʹରͯ͠ߦ͏ɻࢀর͸Ͳ͔͜Ұͭʹରͯ͠ߦ͏ɻ ৗʹ ಉ͡σʔλ ʹ͓ͯ͘͠ load
  23. Groonga-1 Groonga-2 JSONRPC αʔό update location ✗ ͳΜ͔མͪͨ ো֐࣌Ͳ͏͢Δ͔ʁ load

    load
  24. खॱͦͷ1 Groonga-1 load Groonga-2 JSONRPC αʔό update location ✗ •

    Groonga-2Λӡ༻͔Βൈ͍ͯɺGroonga-1ʹߋ৽ɾࢀর ΛدͤΔ ✗
  25. खॱͦͷ2 Groonga-1 Groonga-2 JSONRPC αʔό update location • Groonga-2Λ෮چͤͯ͞࠶౤ೖɻͦͷࡍɺGroonga-2ͷ σʔλ͕ݹ͍Մೳੑ͕͋ΔͨΊɺࢀর͔Β͸͸ͣ͢ɻ

    ͨͩ͠ɺσʔλͷߋ৽͸ड͚෇͚Δɻ load load Select͸μϝʂ load͸OK!
  26. खॱͦͷ3 Groonga-2 • Groonga-2Λӡ༻ͤͭͭ͞ɺMySQLͷϚελʔσʔλ ͱGroongaΛಉظͤ͞ΔεΫϦϓτΛྲྀͯ͠ɺσʔλ Λಉظͤ͞Δɻ εΫϦϓτͰ MySQLͷσʔλͱ ಉظͤ͞Δʂ MySQL

  27. खॱͦͷ4 Groonga-1 Groonga-2 JSONRPC αʔό update location • σʔλͷಉظͷ׬ྃΛ֬ೝͯ͠ɺGroonga-2ʹର͢Δࢀ রΛ໭͢ɻdoneʂ

    selectΛ ෮׆ʂ load load
  28. ͦͷଞ

  29. MapʹҰ౓ʹͨ͘͞ΜPinΛͨͯΔͱ ॏ͘ͳΔ͠͏͍͟

  30. MapʹҰ౓ʹͨ͘͞ΜPinΛͨͯΔͱ ॏ͘ͳΔ͠͏͍͟ • ҰճͷݕࡧͰɺͨ͘͞ΜͷσʔλΛදࣔͯ͠͠·͏ͱ͏͍͟ɻ (લͷϖʔδͷΑ͏ʹͳΔʣ • ͳͷͰ1ճͷݕࡧͷϨεϙϯε͸25݅ఔ౓ʹ͓͍͑ͯ͞Δɻ • ্هͷߜΓࠐΉϩδοΫ͸ɺMap্ʹ͏·͘෼ࢄͤ͞ΒΕΔʢਅΜதʹूத͠ͳ ͍ʣΑ͏ʹ޻෉͍ͯ͠Δɻ

    ※શମͷώοτ݅਺͔Βɺ25ਓఔ౓ʹ͓͑͞ΒΕΔΑ͏ʹɺ_key(user_id)Λม਺ Ͱׂͬͨ༨Γ͕5ͷϢʔβ͚ͩऔಘ͢Δͱ͔ɺͦ͏͍͏ΫΤϦΛ౤͍͛ͯΔɻ • MapΛ֦େ͍ͯ͘͜͠ͱͰɺର৅Ϣʔβ͕ঃʑʹߜΓ͜·Ε͍ͯ͘ͷͰɺ࠷ऴత ʹ͸͢΂ͯͷϢʔβ͕දࣔͰ͖ΔΑ͏ʹͳΔɻ • ͜ͷ͋ͨΓ͸΋ͬͱվળͰ͖Δ͔ͳɻ
  31. iOSʹ͓͚ΔҐஔ৘ใͷऔಘํ๏ • ͜͜͸͍Ζ͍Ζਂ͍ΜͰ͕͢·ͨࠓ ౓ʂ

  32. ޚྱ • ͙ʹΌΒ͞Μʂ • ITج൫ ੴڮ͞Μʂ • mitz͞Μʂ@t_mitz • Yosaku

    ToyamaʂʢPekoͷGroonga୲౰ʣ • Groonga։ൃʹؔΘͬͯΔօ༷ʂʂʂ
  33. Ͳ͏΋ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ