Two different google APIs on the same page - javascript

Is it possible to get two different javascript Google APIs to work on the same page? My goal is to use the autocomplete Google API to get an address to pass into the calculate distance API, allowing the user to autocomplete their address and immediately see the estimated travel time to a predefined location (similar to Uber). I am new to javascript, so I am not sure if there is some trick to solve this problem; any advice?

If the question is "is it possible ?", I could just answer "yes" :).
You can insert autocomplete in HTML that will lead subsequent call to distance API, no problem.

Related

How to get only street/road coordinates via reverse geocoding (Google Maps API)

I'm looking for a solution to get data to create a simple roads-only map.
Within a small area specified by lat/long I need data that allows me to draw custom lines between given street coordinates (start and endpoints are basically enough and only from major streets). Coordinates from intersections are also fine to connect those with my custom lines.
Another approaches would be to get all the major street names within the specified area via reverse geocoding and then - somehow - get coordinates for each of this streets.
There was a similar request a couple years ago:
Get street graph for a game using Google Maps API and I'm wondering is it still a big deal to achieve this kind of technical information in a simple way?
EDIT:
I researched the topic but no result gave me the satisfaction I was looking for. For instance Google's Directions/Roads API are both depending on routes. OSM/Google Maps API are filled with information around a specified geo location but without any technical data I need. To be simple: An Array of intersection/street-point coordinates (are they even called coordinates?!).
I think I'm lost - or even stuck - in terms of my own search phrases. I'm not looking for a copy & paste snippet more like a direction or some hints where to focus next or how it is done.
With the clarification of geocodezip's comment I've found the following related question:
How to get all roads around a given location in OpenStreetMap?
This fully suits my demand to get specific road information within a certain location using OSM instead of Google Maps API.
Many thanks

How can I get the name of the closest gas station printed out using Google Places API for javascript?

I'm pretty new to Javascript, but I want to create a simple app. It must show the name of the closest gas station when a button is clicked. It also must print it using document.write().
I have been looking at the documentation that Google has provided and I am confused about how to use rankBy.DISTANCE routine.
Any help would be appreciated. Thanks!
Get the longitude and latitude of your location through javascript. According to it check whether is there any gas station available within your preferred area. You can get the javascript api from Link is here
To use rank by closest distance see this

passing an array of addresses into the Geocode.geocoder() Google Maps

Description:
I am using Google Maps v3. I have 25 dynamic addresses that I need to geocode at one time. We are currently working on a solution to store the lat/long in a database and remove the need to use Google's resources, but that is still a few months down the road and I need this geocoding functionality now.
Question:
Is there a way that I can send an entire array of full address into the geocode.geocoder() function? I have only seen examples where it was limited to one address at a time.
Disclaimer:
I have searched this site and could not find a solution. I have also google'd this exact question and haven't found anything.
The answer is: No
Some great alternatives: https://gis.stackexchange.com/questions/22108/how-to-geocode-300-000-addresses-on-the-fly
Not too sure if I should delete the question or not; kinda want to leave it up so duplicates aren't made. I would never have thought of the search query "batch processing"

Alternatives to Googles Distance Matrix service?

I am working on a quote calculator that will generate a quote based on mileage between various locations (amongst other conditionals). Up until two days ago, I had planned to use Google's Distance Matrix service until I discovered:
Display of a Google Map
Use of the Distance Matrix service must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.
I had hoped to use only the services that I require:
- Distance by Road Measurement between up to three different locations
- Address Autocomplete Service usable on an input box
- Accurate, reliable service that can provide multiple different routes to create an average distance
I know there are other methods available for this, but I doubt many can be as accurate and reliable as Google, I've found it challenging to find anything comparable to Google Maps for the purposes I require.
So, unless you guys can point me to something that I can use, my only option is to use a Google Map where I don't need it, adding additional loading time and altering the UX design I had planned.
Are there any free services available for what I require (preferably with a JS API)?
On a slightly different note
If I do use a Google map, would it have to be displayed immediately, or could I hide it and add an option to 'Show On Map', and have it .slideToggle revealed?
Unfortunately for the Distance Matrix API, Google strictly says you NEED to display the map in your application:
Use of the Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.
http://developers.google.com/maps/documentation/distancematrix/#Limits
However, what I think is more useful for your need is Google Directions API. The directions API allows you to cover your requirements.
The total distance is returned in the JSON object from the request.
You can select upto as many different locations to find distances between using the Waypoints in your search request. The distances between these locations are then returned in each "leg".
You can obtain the average distance from multiple different routes to your destination by specifying the alternatives parameter in your search request to true. See: http://developers.google.com/maps/documentation/directions/#RequestParameters
Best of all, there is no requirement from Google to display the Google Map in your application when using this service.
I should also mention the drawbacks to this service, if you choose to use it.
The request time it takes to process your request will be slightly longer than if you were to use the Distance Matrix API.
You'll have a lot of unneeded data in the return object, for instance the individual "steps" of the route in the returned json object is not necessary based on your application requirements.
Given the drawbacks, I'd still highly recommend looking into the Directions API for your application.
I don't know if Google Static Maps count as a map, but it should, since it's a Map and from Google.
You could calculate the route and then show it as an image from Static Maps. No extra map loading times required. Only one image.
https://developers.google.com/maps/documentation/staticmaps/#Paths
Many developers have been able to do this with the Bing Maps REST routing service http://msdn.microsoft.com/en-us/library/ff701705.aspx. It requires a bit more development but works well. Here is an example: http://code.msdn.microsoft.com/Bing-Maps-trip-optimizer-c4e037f7
Streetmap and arcserver can solve a vehicle routing problem but it's not free. Read more here: http://www.esri.com/data/streetmap.

Javascript Phone Number Autocomplete

Hi is there anyway using Javascript to get user's current location and autocomplete fields in a form like telephone country code (e.g. in Singapore it is +65) and area code?
It's really difficult, and I'd advise against it because it's loads of effort for very little reward. The best way (most fluid for the user) would be to get the users IP using PHP/ASP/Ruby-on-Rails/whatever and query one of the freely available Geo-IP databases (Google it) to match that to a country, then create your own database of country codes (using this, or similar).
If you really really want to do it using JavaScript, it'll only let you do it in newer browsers, and it'll prompt the user that you want to know their location... a lot of people will wonder why you're asking for this and click no.
// first, check it's supported
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(insertCountryCode);
}
insertCountryCode is a function that you pass. Why? Because the prompt for the user to allow your website to know their location is non-modal, meaning the page will carry on running while it waits for a response, so the function when they do respond will be asynchronous (outside the normal flow). This function is where you look up their location and insert their country code. In this function, use the Google Maps API and pass the latlng parameter to get the country... then you need to find another lookup service which will let you find out the dialing code.
The reason I've explained this is to show you how hard it is. A much simpler alternative would be to have a drop-down box with
<option value="+65">Singapore</option>
and insert the value into the phone number box. That's what I advise you do.

Categories

Resources