Reputation: 95
I am using google maps API to load the google map in my code. Now, I have to give the user an option to manually enter the address when google map is not available. Here, my problem is that when google map is not available browser takes around 2 minute to connect to the API
<script type="text/javascript"
src="<%=requestScheme%>://maps.google.com/maps/api/js?sensor=false&libraries=places">
</script>
and the request is getting aborted due to time out. So, I have to wait 2 minute until to show the option for manually entering the details. Any suggestion to avoid this 2 min time delay when the map is not available. Do I have to set up a time out where I can wait for 30 sec and allow the user to manually enter the if the map is not loading with in that time frame?
Upvotes: 0
Views: 950
Reputation: 95
I was able to resolve my issue by placing the script inside the body tag(end of the body tag). Previously I placed the script inside head tag which took more time to load which in turn blocked other script until it got loaded. This link gave me the idea,
http://stevesouders.com/hpws/js-blocking.php
Basically it is best practice to place the script before the closing body tag. For better understanding please refer this post,
Where should I put <script> tags in HTML markup?
Upvotes: 0
Reputation: 63589
You could check for the existence of the API:
var foundMap = typeof google === 'object' && typeof google.maps === 'object';
if (foundMap) {
// load the map
} else {
// add code for manually entering the address
}
Upvotes: 1