{"id":270,"date":"2013-09-09T08:47:39","date_gmt":"2013-09-09T12:47:39","guid":{"rendered":"https:\/\/www.redline13.com\/blog\/?p=270"},"modified":"2022-01-03T20:00:19","modified_gmt":"2022-01-04T01:00:19","slug":"latlong-sql-where-clause-for-your-database","status":"publish","type":"post","link":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/","title":{"rendered":"Lat\/Long SQL Where Clause for Your Database"},"content":{"rendered":"<p><a href=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.33.06-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-271 alignright\" alt=\"Polygon Approximation of a Circle\" src=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.33.06-AM.png\" width=\"219\" height=\"223\" \/><\/a>We have added an interesting extension to our Zipcode API. This is for applications that have their own database of latitude and longitude positions, but need to calculate items within a certain radius of another latitude\/longitude.<\/p>\n<p>You can try it here &#8211;\u00a0<a href=\"https:\/\/www.zipcodeapi.com\/API#radiusSql\" target=\"_blank\" rel=\"noopener\">https:\/\/www.zipcodeapi.com\/API#radiusSql<\/a>. Hint &#8211; use the Zipcode to Location API to find your specific Lat\/Long.<\/p>\n<p>You specify the latitude and longitude of a center point, the distance\/radius from this location, the field names used in your database for latitude and longitude, and a precision. The higher the precision, the more detailed the SQL string will be and the more accurate the results will be. A precision of 2 gives decent results for short distances. Larger distances might require a higher precision. To make your database queries efficient, you should create an index on the latitude\/longitude pair in your database.<\/p>\n<p>For example, a precision of 1 in the Zipcode API Live Documentation is done with this setup:<\/p>\n<p><a href=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.35.07-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-272\" alt=\"Zipcode API Lat\/Long Setup\" src=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.35.07-AM.png\" width=\"616\" height=\"221\" srcset=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.35.07-AM.png 616w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.35.07-AM-300x108.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>will yield an SQL clause like this:<\/p>\n<p><a href=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.37.18-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-273\" alt=\"SQL for Lat\/Long Polygon\" src=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.37.18-AM.png\" width=\"915\" height=\"189\" srcset=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.37.18-AM.png 915w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.37.18-AM-300x62.png 300w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.37.18-AM-768x159.png 768w\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>While a precision of 4 would yield:<\/p>\n<p><a href=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.39.20-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-274\" alt=\"Lat\/Long Polygon\" src=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.39.20-AM.png\" width=\"900\" height=\"723\" srcset=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.39.20-AM.png 900w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.39.20-AM-300x241.png 300w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.39.20-AM-768x617.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Obviously, the higher the precision, the more points on your polygon and the closer approximation to ta true circle and radius.<\/p>\n<p><a href=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/poly_edges_range.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-275\" alt=\"polygon edges accuracy\" src=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/poly_edges_range.jpg\" width=\"600\" height=\"323\" srcset=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/poly_edges_range.jpg 600w, https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/poly_edges_range-300x162.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have added an interesting extension to our Zipcode API. This is for applications that have their own database of latitude and longitude positions, but need to calculate items within a certain radius of another latitude\/longitude. You can try it here &#8211;\u00a0https:\/\/www.zipcodeapi.com\/API#radiusSql. Hint &#8211; use the Zipcode to Location API to find your specific Lat\/Long. You specify the latitude and longitude of a center point, the distance\/radius from this location, the field names used in your<a class=\"more-link\" href=\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\">Read More &rarr;<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,14],"tags":[308,559],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-richardfriedman","4":"post-270","6":"format-standard","7":"category-blog","8":"category-zipcode-api","9":"post_tag-latlong","10":"post_tag-zipcode-api"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.12 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Lat\/Long SQL Where Clause for Your Database - RedLine13<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lat\/Long SQL Where Clause for Your Database - RedLine13\" \/>\n<meta property=\"og:description\" content=\"We have added an interesting extension to our Zipcode API. This is for applications that have their own database of latitude and longitude positions, but need to calculate items within a certain radius of another latitude\/longitude. You can try it here &#8211;\u00a0https:\/\/www.zipcodeapi.com\/API#radiusSql. Hint &#8211; use the Zipcode to Location API to find your specific Lat\/Long. You specify the latitude and longitude of a center point, the distance\/radius from this location, the field names used in yourRead More &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\" \/>\n<meta property=\"og:site_name\" content=\"RedLine13\" \/>\n<meta property=\"article:published_time\" content=\"2013-09-09T12:47:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-04T01:00:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.33.06-AM.png\" \/>\n<meta name=\"author\" content=\"Rich Friedman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rich Friedman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\"},\"author\":{\"name\":\"Rich Friedman\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/0fadb7f3ef665407f3c93c8ec84e741a\"},\"headline\":\"Lat\/Long SQL Where Clause for Your Database\",\"datePublished\":\"2013-09-09T12:47:39+00:00\",\"dateModified\":\"2022-01-04T01:00:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\"},\"wordCount\":210,\"publisher\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\"},\"keywords\":[\"Lat\/Long\",\"Zipcode API\"],\"articleSection\":[\"Blog\",\"ZipCode Api\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\",\"name\":\"Lat\/Long SQL Where Clause for Your Database - RedLine13\",\"isPartOf\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\"},\"datePublished\":\"2013-09-09T12:47:39+00:00\",\"dateModified\":\"2022-01-04T01:00:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.redline13.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lat\/Long SQL Where Clause for Your Database\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"name\":\"RedLine13\",\"description\":\"(Almost) Free Load Testing in the Cloud\",\"publisher\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.redline13.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\",\"name\":\"RedLine13\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"contentUrl\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"width\":300,\"height\":68,\"caption\":\"RedLine13\"},\"image\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/0fadb7f3ef665407f3c93c8ec84e741a\",\"name\":\"Rich Friedman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8651ce662fc18353b90c1922f9d29efb01173afa5500224b4d9a355d858a7bd9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8651ce662fc18353b90c1922f9d29efb01173afa5500224b4d9a355d858a7bd9?s=96&d=mm&r=g\",\"caption\":\"Rich Friedman\"},\"sameAs\":[\"http:\/\/richardfriedman@yahoo.com\"],\"url\":\"https:\/\/www.redline13.com\/blog\/author\/richardfriedman\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lat\/Long SQL Where Clause for Your Database - RedLine13","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/","og_locale":"en_US","og_type":"article","og_title":"Lat\/Long SQL Where Clause for Your Database - RedLine13","og_description":"We have added an interesting extension to our Zipcode API. This is for applications that have their own database of latitude and longitude positions, but need to calculate items within a certain radius of another latitude\/longitude. You can try it here &#8211;\u00a0https:\/\/www.zipcodeapi.com\/API#radiusSql. Hint &#8211; use the Zipcode to Location API to find your specific Lat\/Long. You specify the latitude and longitude of a center point, the distance\/radius from this location, the field names used in yourRead More &rarr;","og_url":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/","og_site_name":"RedLine13","article_published_time":"2013-09-09T12:47:39+00:00","article_modified_time":"2022-01-04T01:00:19+00:00","og_image":[{"url":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-09-at-8.33.06-AM.png"}],"author":"Rich Friedman","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rich Friedman","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#article","isPartOf":{"@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/"},"author":{"name":"Rich Friedman","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/0fadb7f3ef665407f3c93c8ec84e741a"},"headline":"Lat\/Long SQL Where Clause for Your Database","datePublished":"2013-09-09T12:47:39+00:00","dateModified":"2022-01-04T01:00:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/"},"wordCount":210,"publisher":{"@id":"https:\/\/www.redline13.com\/blog\/#organization"},"keywords":["Lat\/Long","Zipcode API"],"articleSection":["Blog","ZipCode Api"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/","url":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/","name":"Lat\/Long SQL Where Clause for Your Database - RedLine13","isPartOf":{"@id":"https:\/\/www.redline13.com\/blog\/#website"},"datePublished":"2013-09-09T12:47:39+00:00","dateModified":"2022-01-04T01:00:19+00:00","breadcrumb":{"@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.redline13.com\/blog\/2013\/09\/latlong-sql-where-clause-for-your-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.redline13.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Lat\/Long SQL Where Clause for Your Database"}]},{"@type":"WebSite","@id":"https:\/\/www.redline13.com\/blog\/#website","url":"https:\/\/www.redline13.com\/blog\/","name":"RedLine13","description":"(Almost) Free Load Testing in the Cloud","publisher":{"@id":"https:\/\/www.redline13.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.redline13.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.redline13.com\/blog\/#organization","name":"RedLine13","url":"https:\/\/www.redline13.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","contentUrl":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","width":300,"height":68,"caption":"RedLine13"},"image":{"@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/0fadb7f3ef665407f3c93c8ec84e741a","name":"Rich Friedman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8651ce662fc18353b90c1922f9d29efb01173afa5500224b4d9a355d858a7bd9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8651ce662fc18353b90c1922f9d29efb01173afa5500224b4d9a355d858a7bd9?s=96&d=mm&r=g","caption":"Rich Friedman"},"sameAs":["http:\/\/richardfriedman@yahoo.com"],"url":"https:\/\/www.redline13.com\/blog\/author\/richardfriedman\/"}]}},"_links":{"self":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":1,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":8641,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions\/8641"}],"wp:attachment":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}