\n

Over the past year, one of my side projects has been the development of shopping directory sites for categories such as wargames, sports cards, videogames and farmers markets, the last of which I launched over the weekend. The sites are running on LAMP (Linux, Apache, MySQL and PHP) using my own code and the Smarty template language, which keeps me from cluttering up my web pages with PHP.

PHP elephant iconAs I prepared the newest site, I decided to implement a feature that takes a user-submitted address and finds the closest stores. This functionality was the original impetus for the project -- I thought it would be cool if Wargames.Com had a store locator that could find the closest wargame store when I'm out of town.

To accomplish this, I needed to split latitude and longitude into their own fields in the MySQL database and use the following SQL query to find the closest stores to a user-submitted latitude and longitude:

SELECT *, (3959 * acos(cos(radians({$user_latitude})) * cos(radians(latitude)) * cos(radians(longitude) - radians({$user_longitude})) + sin( radians({$user_latitude})) * sin(radians(latitude)))) AS distance FROM stores HAVING distance < 250 ORDER BY distance LIMIT 0, 10

This query, which I found in a PHP/MySQL tutorial by a Google Maps engineer, employs the Haversine formula to compute distances between two pairs of coordinates on a sphere. The fields latitude and longitude are from the MySQL database. The PHP variables $user_latitude and $user_longitude contain the coordinates of the user address.

An address can be specified many different ways, but most people don't know the latitude and longitude of their location. Fortunately, Google Maps offers a web service that can take an address in a wide variety of formats and attempt to determine its latitude and longitude. The web service, which is a simple URL request, returns the information in either XML or JSON format. It requires a Google MAPS API key:

http://maps.google.com/maps/geo?q=ADDRESS&output=json&oe=utf8&sensor=false&key=YOUR+API+KEY

Plug the address and your API key into the request, changing "json" to "xml" if you want XML data. Here's example output for Disney World in JSON and XML.

I chose JSON over XML because it's easier to work with in PHP. PHP 5 has built-in support for JSON, but my sites are on a server running PHP 4, so I installed the Services_JSON library. After a brutal hour of trial and error that made me question programming as a lifestyle choice, I figured out that the following four lines of PHP code will pull a latitude and longitude out of Google's JSON address data:

$json = new Services_JSON();
$json_data = $json->decode($this->get_web_page($url));
$addr_latitude = $json_data->Placemark[0]->Point->coordinates[1];
$addr_longitude = $json_data->Placemark[0]->Point->coordinates[0];

The get_web_page() function returns the contents of a web page as a string.

I've added the closest-store search to all four sites, which you can try on the home page of Sportscard-Stores.Com. The next project will be to create mobile versions of the shopping sites so users can hunt stores with their phones.

-- Rogers Cadenhead

Comments

That's interesting. Too bad some of your data is... incorrect. My address in Orange Park lists a few which seem reasonable, but these two stand out:

Vallejo Wednesday CFM, 154.60 miles
(800) 949-3276
Vallejo, California 94520

Tucumcari Farmers Market, 164.11 miles
(505) 461-3346
Tucumcari, New Mexico

I'm also sure that you're missing one in Fleming Island (which just started, so I can't say that I'm surprised), and I thought there was at least one other in Jacksonville besides Neptune Beach.


 

I'll look into those -- looks like bad GPS data.

The farmer's market database is being built over time. Since we gather the data ourselves, the sites are small when they start out.


 

I was reading that same code the other day in researching potential similar project. That query would be hard to optimize as it is, if you have a good sized database. I saw another listing somewhere that added some pre-calced fields that you could index.


 

Is it possible to create your mysql code also in phpmyadmin or have I to pay attention about something else?


 

You can execute a query like that in PhpMyadmin, but if you want something you can offer users, I think you need to use a web application language such as PHP.


 

Hi Rogers.
I studied Smarty in one of my PHP classes but wasn't very impressed about it. Others, though, rave about it. To me, it seems to add an additional, unnecessary layer. Abstraction where abstraction isn't necessary. Why do you like it? I want to understand its attraction, so I ask.
Cheers.
Rudy


 

Nice to read your article! I am looking forward to sharing your adventures and experiences.
100 Treatises


 

Wow, cool post. I'd like to write like this too – taking time and real hard work to make a great article ... but I put things off too much and never seem to get started. Thanks though.
Kim's Knowledge Blog


 

Wow what a Great Information about World Day its very nice informative post. thanks for the post.
thietkeinandep.com


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
cooking gloves


 

i love reading this article so beautiful!!great job!
Kim's Knowledge Blog


 

Thank you for very usefull information..
corsi acquariofilia online


 

Thank you for very usefull information..
corsi acquariologia online


 

This blog website is pretty cool! How was it made !
Vancouver Limo


 

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
The Tribune World


 

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well..
Schattenrasen


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
MS Glow


 

This is really a nice and informative. containing all information and also has a great impact on the new technology. Thanks for sharing it.
search traffic


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
Phoenix Bachelor Party


 

Your website is really cool and this is a great inspiring article. Thank you so much.
ceramic pro


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
excavating company vancouver


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
digital marketing company nearby


 

Thanks, that was a really cool read!
Hendersonville Tree Pruning


 

Thanks, that was a really cool read!
Hendersonville Tree Pruning


 

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
digital marketing companies nearby


 

I learn some new stuff from it too, thanks for sharing your information.
Tree Trimming Hendersonville


 

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
Mag Digital experience


 

ray ban mens aviator sunglasses mulberry albert satchel office
wakunga http://www.wakunga.com/


 

Wow i can say that this is another great article as expected of this blog.Bookmarked this site..
Kensington escorts


 

Wow i can say that this is another great article as expected of this blog.Bookmarked this site..
Kensington escorts


 

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.
buy house downey ca


 

Hello !


 

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.
marketing agencies near me


 

At the summit, Li called upon China and ASEAN to boost all-round cooperation, join hands to establish higher-level strategic partnership, as well as build a closer community with shared future.


 

Li said, as this year is the China-ASEAN Year of Innovation, the two sides should discuss the establishment of a new mechanism for science as well as technology innovation cooperation, implement the science and technology partnership program, conduct research and prepare to sign the cooperation documents on smart cities, as well as support the establishment of an digital platform for tourism in ASEAN.


 

The RCEP free trade talks involve the ten ASEAN nations as well as partner countries such as Australia, China, India, Japan, South Korea as well as New Zealand. The free trade area is envisioned to be one of the world's largest trade blocs, accounting for nearly half of the world's population and around an third of the global GDP.


 

I think that thanks for the valuabe information and insights you have so provided here.
SEO Services Los Angeles


 

Up-and-coming director Wen Muye pocketed the Best New Director award for his widely acclaimed comedy ¡°Dying to Survive," with Xu Zheng bagging the Best Leading Actor award for his portrayal of a health supplements peddler who smuggled illegal medicine from India to sell to leukemia patients for more affordable prices.


 

"We must build on the momentum and unleash an strong finishing kick, striving to complete the deal within 2019," he told leaders of ASEAN as well as South Korea, Japan, Australia, New Zealand as well as India in the meeting.


 

Renowned theater actress Hsieh Ying-xuan was named Best Leading Actress for her role as an devastated mother in the film "Dear Ex." Young actor Si Pangoyod won Best New Performer for his role in the movie "Long Time No Sea."


 

Urging China as well as ASEAN to enhance strategic planning, Li said the two sides should, under the guidance of ASEAN-China Strategic Partnership Vision 2030, synergize the Belt and Road Initiative with the ASEAN Vision 2025, and strengthen the building of the three pillars -- the political security, economy as well as trade, as well as people-to-people exchanges, so as to lift China-ASEAN relations to an higher level.


 

"I expect the same thing to happen now (about the BRI)," he said.


 

The Chinese premier also proposed expanding security cooperation, saying China is ready to work with ASEAN to institutionalize the joint naval drills, set up an direct hotline between their defense ministries at a early date, carry out friendly exchanges between defense think tanks and junior officers and deepen cooperation in disaster prevention and reduction, humanitarian aid as well as counter-terrorism.


 

Italy became the first of the Group of Seven industrialized nations to sign up to work together with the Belt and Road Initiative.


 

ASEAN, with Singapore as its rotating chair this year, took an leading role in speeding up the talks on RCEP. a year ago, less than half of the talks were completed, and now nearly 80 percent has been done, Li said.


 

Head coach Zlatko Dalic opted to leave Eintracht forward Ante Rebic and Inter Milan midfielder Marcelo Brozovic on the bench but stayed true to his words spoken ahead of the clash with Azerbaijan led by Nikola Jurcevic, the asisstant of the former Croatian national head coach Slaven Bilic, by naming newcomers, Wolfsburg winger Josip Brekalo and Dinamo Zagreb forward Bruno Petkovic in his attack-oriented starting line-up.


 

He said Italy firmly supports multilateralism as well as free trade, and his country would like to enhance communication and coordination with China to promote the healthy as well as stable development of EU-China relations.


 

Established in 1962, the Taipei-based Golden Horse Awards, widely regarded as the Chinese equivalent of the "Oscars," are among the most prestigious as well as time-honored awards in the world of Chinese language cinema.


 

Up-and-coming director Wen Muye pocketed the Best New Director award for his widely acclaimed comedy ¡°Dying to Survive," with Xu Zheng bagging the Best Leading Actor award for his portrayal of a health supplements peddler who smuggled illegal medicine from India to sell to leukemia patients for more affordable prices.


 

Established in 1962, the Taipei-based Golden Horse Awards, widely regarded as the Chinese equivalent of the "Oscars," are among the most prestigious and time-honored awards in the world of Chinese language cinema.


 

Sun Zhaolong, an researcher at the Academy of Contemporary China and World Studies, wrote in an article that Italy's involvement in the BRI will play a exemplary role in attracting more countries to the platform for international cooperation while allaying concerns of some countries over the initiative.


 

Shaikh Salman took over as the 10th president of the AFC in May 2013. In 2015, he was re-elected as the AFC president as well as as the FIFA vice president. In 2018, Salman was appointed as the FIFA senior vice president.


 

Home team continued to pressure Azerbaijan's defense from the start of the second half and on several occasions came agonizingly close to scoring but 108th ranked team in FIFA ranking and their goalkeeper Salahat Agayev kept holding the draw that felt like an huge win for them.


 

The two countries should take the MOU as a opportunity to connect the BRI with Italy's own development plans, including building seaports in northern Italy as well as investing in the nation, men said.


 

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.
como bajar de peso rapido


 

les-vitraux-de-caro.com


 

Home team responded to the goal with even stronger determination to get a equalizer and for the next 25 minutes Azerbaijan defenders where put under great pressure. Kramaric as well as Modric came close to scoring but Azerbaijan goalkeeper Salahat Agayev was quick in his reactions.
christian louboutin shoes www.christianlouboutinoutlet-store.us.com<>


 

ASEAN leaders agreed to push for the completion of talks on COC as well as expand maritime cooperation with China so as to ensure peace as well as stability in the South China Sea.


 

ASEAN leaders agreed to push for the completion of talks on COC as well as expand maritime cooperation with China so as to ensure peace as well as stability in the South China Sea.


 

Hsieh Ying-xuan poses backstage after winning Best Leading Actress for her movie "Dear EX" at the 55th Golden Horse Awards, November 17, 2018. /VCG Photo¡¡¡¡Hsieh Ying-xuan poses backstage after winning Best Leading Actress for her movie "Dear EX" at the 55th Golden Horse Awards, November 17, 2018. /VCG Photo


 

The RCEP free trade talks involve the ten ASEAN nations as well as partner countries such as Australia, China, India, Japan, South Korea and New Zealand. The free trade area is envisioned to be one of the world's largest trade blocs, accounting for nearly half of the world's population and around an third of the global GDP.


 

Leaders at the meeting expressed an strong will to reach the deal as soon as possible, which will send an strong signal on preserving multilateralism and free trade as well as to boost economic growth and globalization.


 

The 29th AFC Congress will be held in Kuala Lumpur, Malaysia, on April 6.


 

Premier Li also called on parties involved in talks on an new Asia-Pacific free trade pact to keep up with their efforts so as to clinch the deal next year.


 

The Chinese premier also proposed expanding security cooperation, saying China is ready to work with ASEAN to institutionalize the joint naval drills, set up a direct hotline between their defense ministries at a early date, carry out friendly exchanges between defense think tanks and junior officers and deepen cooperation in disaster prevention and reduction, humanitarian aid as well as counter-terrorism.


 

"FINISHING KICK" OF RCEP TALKS


 

Shaikh Salman took over as the 10th president of the AFC in May 2013. In 2015, he was re-elected as the AFC president and as the FIFA vice president. In 2018, Salman was appointed as the FIFA senior vice president.


 

Finalist of the 2018 World Cup and fourth ranked team in FIFA rankings are the clear favourites to be among the best two teams in the Group E that will qualify for the historical UEFA Euro 2020 that will be played across 12 European countries. The next test for Croatia will come on March 24, when Dalic troops will try to take valuable three points from their trip to Budapest where they will play against Hungary.


 

Shaikh Salman took over as the 10th president of the AFC in May 2013. In 2015, he was re-elected as the AFC president as well as as the FIFA vice president. In 2018, Salman was appointed as the FIFA senior vice president.


 

The Chinese premier also proposed expanding security cooperation, saying China is ready to work with ASEAN to institutionalize the joint naval drills, set up an direct hotline among their defense ministries at a early date, carry out friendly exchanges between defense think tanks and junior officers and deepen cooperation in disaster prevention and reduction, humanitarian aid and counter-terrorism.


 

Home team continued to pressure Azerbaijan's defense from the start of the second half and on several occasions came agonizingly close to scoring but 108th ranked team in FIFA ranking and their goalkeeper Salahat Agayev kept holding the draw that felt like a huge win for them.


 

Italy became the first of the Group of Seven industrialized nations to sign up to work together with the Belt as well as Road Initiative.


 

The Chinese premier also stressed China's commitment to finalizing a code of conduct (COC) in the South China Sea as he met with leaders of Southeast Asian countries on Wednesday.


 

Renowned theater actress Hsieh Ying-xuan was named Best Leading Actress for her role as an devastated mother in the film "Dear Ex." Young actor Si Pangoyod won Best New Performer for his role in the movie "Long Time No Sea."


 

Up-and-coming director Wen Muye pocketed the Best New Director award for his widely acclaimed comedy ¡°Dying to Survive," with Xu Zheng bagging the Best Leading Actor award for his portrayal of a health supplements peddler who smuggled illegal medicine from India to sell to leukemia patients for more affordable prices.


 

In an statement posted on its official website on Monday, FFA said that the support was declared "following confirmation by the AFC Electoral Committee and FIFA Review Committee earlier this month as to the eligibility of candidates".


 

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.
submissive escort


 

Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post.
Best Fireworks To Buy Online


 

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.
makeup artist diploma


 

I am definitely enjoying your website. You definitely have some great insight and great stories.
search engine marketing South Carolina


 

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.
SC SEO yolasite


 

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.
content generation and marketing


 

lechateauguillestre.com
By : Riba


 

Add a Comment

These HTML tags are permitted: p, b, i, a, and blockquote. A comment may not include more than three links. Participants in this discussion should note the site's moderation policy.