How to verify the distance between 2 canadian zip code - javascript

I would like to know what is the best way to get the distance between 2 (zip code) or postal code in Canada. I have seen post about MySQL doing so with US zip code.
Or I guess that I could probably translate a zip code to coordinates and then triangulate distances? If anyone can share tips on this I would apreciate!
Im working with Angular JS and Node JS but I could do with PHP as well.
An Api should be free and be able to handle large ammount of querys.
Thank You

Google Maps API can do it, by setting origin and destination on the distancematrix API.
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=M4C4Y7&destinations=H1A0A2

Related

MapBox GL JS: Get lat and long coordinates from string Address that is set through code

I am using Mapbox GL JS to show certain location marked on the map.
I need to set location through JavaScript code and I don't know the lat and long coordinates, I only have an address in string form (example: "address, city, country" or some similar format).
I have searched a lot on the internet, but the only way that I have found for doing this in Mapbox GL JS is by using Geocoder input control, but I don't want to input location through it, I want to set Address through code and then have it marked on map when the map loads.
Is it possible to do this in Mapbox GL without knowing lat and long coordinates? How can I do that?
Thanks in advance! Best regards!
You can use the Mapbox Geocoding API without the Geocoder control. You have to compose your url (and encode it).
Always consider you could get more than one result in the featureCollection response depending your params, so finally you have to refine the results with some of the attributes allowed such as proximity and limit. At the beginning is a bit of try and error task, but after some practice it's quite accurate.
Here you have an example url for the address 123 Main St Boston MA 02111, filtering the results in United States only.
https://api.mapbox.com/geocoding/v5/mapbox.places/123%20Main%20St%20Boston%20MA.json?country=US&access_token=pk.eyJ1IjoianNjYXN0cm8iLCJhIjoiY2s2YzB6Z25kMDVhejNrbXNpcmtjNGtpbiJ9.28ynPf1Y5Q8EyB_moOHylw
This will return 5 streets in the Massachusetts state.
I recommend you to read the documentation in forward geocoding, and also the section on address geocoding format to compose properly the url.

Extracting Data from a Webpage

For my school project, I need the data on this website:
https://services2.hdb.gov.sg/web/fi10/emap.html
Specifically, I need the longitude and latitude, address, flat type and the number of units of the flat type in csv or excel format so that I can do some spatial analysis.
How do I create an automated process to get all the data from the website and not clicking all the individual buildings?
Appreciate any assistance on this. Thank you.
I got a look at the network traffic when this site is querying it's data. There you can find the XHR-Requests where also the streetname and other things are written down. You may use this to collect your data.

How to get postal code from current location

I'm doing restaurant search engine for my project and I'm stucked with current location.. I can get my lat and lng from navigator (geolocation HTML5).
The point is, that I need postal code, not lat and lng. The only idea I had was to get that lat and lng and connect with postal code using some API.
I've found something like this:
http://api.geonames.org/findNearbyPostalCodes?lat=52.198500&lng=-2.219200&maxRows=1&username=demo
How can I refer to the post code from that API? The best with javascript?
Have you got maybe other ideas? I've got one button and after clicking on that button, I want postcode from my location in text input.
Would you be able to make an API to the following Service and convert the data?
Please look at the following and let me know if you need help Consuming the API..
https://docs.mapbox.com/api/search/#geocoding

how to use islocationOnEdge function to find coordinates on/near a path of google maps api on server side

this question is an extension to the question on Finding particular cities along your Path but am including all the details.
google.maps.geometry.poly.isLocationOnEdge(LatLngOfDbCoordinate,new google.maps.Polyline({path:google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline)}),0.00001);
1) can i run this above line of code for many(eg:10000) (LatLngOfDbCoordinate stored in the database) at the server side as javascript inside the php code with Node.JS ?
2)if yes then could you please tell how should i go about it else
3)could you please tell me how to execute this code via php or with some other classes like http://luktek.com/Blog/2011-02-03-google-maps-routeboxer-in-php (from the stack overflow link at the top)?
And could you please tell me how to use isLocationOnEdge() function with the routeboxer class mentioned above?
4)Is there any other easier way to use isLocationOnEdge() or any other method at the server side to which i am not aware of ?
5) Is there any usage limits to use the function isLocationOnEdge() on server side ? As this is the function of the geometry library and i would only be using this functions boolean return values to display the coordinates which are on/near the polyline are usage limits applicable?
6)And would it be useful to store the overview polyline of routes in the db(cause can be very lengthy in case of large routes) or should i make a request everytime to google url service by sending them start and destination coordinates and using the overview polyline which i recieve as JSON or XML to pass in isLocationOnEdge()? Please specify the reason.
Please Help
Thanks in advance
I had the same problem. But as my application was in android only with the server side is in nodejs, decided to make the implementation in android. I used the PolyUtil class that has the same functions.
http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/PolyUtil.html
But if you really need implement this code in javascript server side you can try to recreate the functions of PolyUtil class. In it you will find the complete code of isLocationOnEdge
https://github.com/jefersondeoliveira/android-hackathon/blob/master/google-maps-utils/library/src/com/google/maps/android/PolyUtil.java
Hope this helps.
bye

Google maps V3 search problems

I have been stuck at this problem for quite a while. I have a database with a little over 100 locations. And I am trying to write a page that will display the closest location to the user. Right now I am using PHP to display the locations in hidden fields and using Javascript to get and display the user location, and to get the distances from the user location(Distance Matrix). The problem I am running into is that I am getting the OVER_QUERY_LIMIT error after about 16 requests. I am getting the error from the distance matrix.
About the OVER_QUERY_LIMIT check the Usage Limits on Distance Matrix API, it sounds to
me you're just going faster than 100 elements per 10 seconds.
Check this Store locator link for better understanding of Finding locations nearby with MySQL
http://code.google.com/apis/maps/articles/phpsqlsearch.html

Categories

Resources