j'ai ci-dessous procédure de magasin je veux vérifier la distance de ma voiture latitude longitude qui geofence plus proche si distance en mètre moins de 500 montrer geofence id qui geofence id plus proche voiture latitude longitude.if voiture latitude longitude polygone ID polygone de présentation et si id rectangle show rectangle je suis nouveau dans le serveur SQL qui est pourquoi je suis ici s'il vous plaît aidez-moi professionnels Je suis très reconnaissant à vous, une table de démonstration sont en lien partagé,comment obtenir la distance dans le compteur
question and demo table is here
CREATE TABLE CarDistance
(
ID int IDENTITY(1,1) PRIMARY KEY,
car_id int,
latitude float,
longitude float
)
insert into CarDistance values(1234, '52.582191','-2.878418')
CREATE TABLE tblgeofencing2
(
ID int IDENTITY(1,1) PRIMARY KEY,
car_id int,
ShapeType varchar(255),
PolygonLatLng varchar(max),
minlatitude [float] NULL,
[minlongitude] [float] NULL,
[maxlatitude] [float] NULL,
[maxlongitude] [float] NULL,
)
insert into tblgeofencing2 values(123, 'polygon','24.835300590037598 67.06858277320862,24.835933468801272 67.06929624080658,24.83532979989791 67.07035303115845,24.83454113125045 67.0697683095932,24.835300590037598 67.06858277320862',NULL,NULL,NULL,NULL)
insert into tblgeofencing2 values(1234, 'rectangle','NULL','52.582191','-2.878418','52.233687','-2.702637')
Alter PROCEDURE [dbo].[Sp_CheckCarStatusMeter]
DECLARE @g GEOGRAPHY,
@ID INT,
@curVal INT,
@preVal INT ,
@CarSuggested INT,
@carlatprevious VARCHAR(10),
@carlongprevious VARCHAR(10),
@AllLatitudeLongitude VARCHAR(255),
@pprevious GEOGRAPHY
DECLARE SuggestCursor CURSOR FOR
SELECT TOP 100 rtha.car_id , rtha.latitude,
rtha.longitude
FROM CarDistance rtha WHERE rtha.car_id = 123;
OPEN SuggestCursor;
FETCH NEXT FROM SuggestCursor INTO @CarSuggestedID , @carlatprevious , @carlongprevious;
WHILE (@@FETCH_STATUS = 0)
BEGIN
DECLARE ShapeCursor CURSOR FOR
SELECT g.ID, @CarSuggestedID, g.ShapeType FROM tblgeofencing AS g
WHERE car_id [email protected]
FETCH NEXT FROM ShapeCursor INTO @ID , @CarIdx , @ShapeType;
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF (@ShapeType = 'polygon')
BEGIN --Polygon IF
PRINT 'polygon if';
SELECT @GeofenceIDnew = g.GeoFenceId, @minY = g.PolygonLatLng ROM tblgeofencing AS g
WHERE g.ID = [email protected]
SET @g = geography ::STPolyFromText('POLYGON((' + @AllLatitudeLongitude + '))', 4326);
SET @pprevious = geography ::STPointFromText(
'POINT(' + @carlatprevious + ' ' + @carlongprevious + ')', 4326 );
SELECT @preVal = @g.STIntersects(@pprevious)
PRINT @preVal
IF @curVal = 1 AND @preVal = 0
BEGIN
PRINT 'Enter In GEOFENCE';
SELECT @geofencename = geofenceName,
@geofenceidforresult = ID
FROM tblgeofencing where ID = @CarSuggestedID;
INSERT INTO tblGeofenceCarStatus
VALUES
(
@CarSuggestedID, @geofenceidforresult,@geofencename,
@gpstime, @g.STDistance(@pprevious), 'Enter');
END
ELSE
BEGIN
Print Not in Geofence
END
END; --- END POLYGON IF
FETCH NEXT FROM ShapeCursor INTO @ID , @CarIdx , @ShapeType;
END; --- END CHECK GEOFENCING RECTANGLE OR CIRCLE OR PLYGON
FETCH NEXT FROM SuggestCursor INTO @CarSuggestedID , @carlatprevious , @carlongprevious;
END;
CLOSE ShapeCursor;
DEALLOCATE ShapeCursor;
CLOSE SuggestCursor;
DEALLOCATE SuggestCursor;
SELECT * FROM tblGeofenceCarStatus;
END;
END; --- END SP BEGIN STATEMENT