Thursday 15 May 2014

javascript - How to check if a LatLng is valid in Google StreetView using JS and PHP -


I am trying to implement a php service which will take $ _ GET ("LAT") Verify that if it is valid or not against Javascript and $ _GET ("LNG") and Google StreetView API v3 , then verify it. If it is, then it is OK, or NOK returns.

I have a sense of JS code to accomplish this:

  var latLng = new google.maps.LatLng (12.121221, 78.121212); StreetViewService.getPanoramaByLocation (latLng, STREETVIEW_MAX_DISTANCE, Function (Street View Display Data, Status) {If (Status === google.maps.StreetViewStatus.OK) {// OK} Other {// No Correct}});   

I am not able to tie everything together, which means PHP and JS, so that it can work.

Can anyone help me?

Edit 1:

This is the code I came for yet, but it does not work:

  & lt ;? Php header ("content-type: app / javascript"); ? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body onload = "checkValid ()" & gt; & Lt; Script src = "https://maps.googleapis.com/maps/api/js?v=3.exp&symsource=true" & gt; & Lt; / Script & gt; & Lt; Script language = "text / javascript" & gt; Function check valid () {var streetViewService = new google.maps.StreetViewService (); Var STREETVIEW_MAX_DISTANCE = 100; Var latLng = New google.maps.LatLng (& lt ;? Php $ _GET ("LAT")? & Gt ;, & gt; Php $ _GET ("LNG")? & Gt;); StreetViewService.getPanoramaByLocation (latLng, STREETVIEW_MAX_DISTANCE, function (Street ViewTerror Data, Status) {If (Status === google.maps.StreetViewStatus.OK) {Warning ('OK');} and {Warning ('No');} }); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

If you want to use JS to verify lat and lng There is a need to get the $ _ GET parameter in JS:

  var LAT = '& lt ;? = Isset ($ _GET ['LAT'])? $ _GET ['LAT']: 91? & Gt; '; Var LNG = '& lt ;? = Isset ($ _GET ['LNG'])? $ _GET ['LNG']: 181? & Gt; '; Var latLng = new google.maps.LatLng (LAT, LNG); StreetViewService.getPanoramaByLocation (latLng, STREETVIEW_MAX_DISTANCE, Function (Street View Display Data, Status) {If (Status === google.maps.StreetViewStatus.OK) {// OK} Other {// No Correct}});   

I have used a simple test statement which asks if GET is available, if it is, then add it to JS variable, if it Do not add value outside the wave and LNG limit will automatically fail Google Maps API.

No comments:

Post a Comment