Solved

How to Use Google Map API From Stored Procedure

Posted on 2016-10-05
5
105 Views
Last Modified: 2016-10-17
Hi Guys,

Are there any tutorials on how to use google map API and connect it with the stored procedure to make the marker points?

regards
0
Comment
Question by:shah36
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:shah36
ID: 41829568
Hi Terry,

Sorry i should have been more specific. So the requirement is that if a user types an address and the radius. The google maps should create the markers on the suppliers within that radius. Now the address of the suppliers are saved within our SQL Server database with Lat ad Long.

regards
0
 
LVL 27

Accepted Solution

by:
Zberteoc earned 500 total points
ID: 41830341
You can't use Google APIs from SQL server and they were never intended for that. SO your problem, if I understand correctly is this:

From an application you get a location in the form of lat-long coordinates, a radius and then you have to find all the suppliers within that radius by querying the supplier table in the database.

This can be done in 2 ways:

1. Using the lat long given by the user and select all the rows from the table where the distance between supplier lat long and the user lat long <= radius

2. You can use the spatial datatypes to store the location of the suppliers and then buffer the user location by the radius and select from the table all the suppliers where location intersects the user buffered location.


I would recommend the first approach because is simpler and doesn't need spatial datatype which are not familiar for everyone. For this you need a distance function to be created in teh same database where the suppliers table is:
CREATE FUNCTION [dbo].[fnDistance] 
( 
	@Lat1 decimal(11, 8), 
	@Lng1 decimal(11, 8),
	@Lat2 decimal(11, 8),
	@Lng2 decimal(11, 8)
)
RETURNS decimal(10, 6) -- max 10km
AS
BEGIN

if abs(@Lat2-@Lat1) > 1 or abs(@Lng2-@Lng1) > 1
	return 10
declare	@distance decimal(30, 8)

declare @R as int
select @R = 6371000

declare @dLat as decimal(21, 17)
declare @dLng as decimal(21, 17)
select @dLat = (@Lat2-@Lat1) * pi() / 180
select @dLng = (@Lng2-@Lng1) * pi() / 180

declare @a as decimal(18, 18)
declare @c as decimal(18, 18)
select @a = Sin(@dLat / 2) * Sin(@dLat / 2) +
	Cos(@Lat1 * pi() / 180) * Cos(@Lat2 * pi() / 180) * Sin(@dLng /2) * Sin(@dLng / 2);
select @c = 2 * Atn2(Sqrt(@a), Sqrt(1-@a))

select @distance = (@R * @c )/1000-- % 10000

return @distance 


END

Open in new window

Use this function to find the suppliers like this:
declare
	@UserLat decimal(11,8)=42.998282,
	@UserLong decimal (11,8)=-81.243822,
	@radius int =1500 -- radius should be in meters
	
select 
	* 
from 
	Suppliers 
where
	[dbo].[fnDistance](SupplierLat, SupplierLong, @UserLat, @UserLong)<@radius

Open in new window

0
 

Author Closing Comment

by:shah36
ID: 41846614
Thanks a lot it did help.
Kindest regards
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates the importance of annotations in Google Analytics and how they should be used to document changes made to a site, Google updates (Ex: Panda & Penguin), marketing campaigns, and any other events that might have contri…
This Micro Tutorial demonstrates how to create custom reports and the secrets of determine the metrics and dimensions for your data that works best with your needs.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question