To integrate Oracle APEX with Google Maps | Find Your Location,
I have followed below steps.
Step 1: Google API Key must be obtained. Get Google API Key.
Step 3: Create static region with static ID: googlemap.
Step 4: Add custom CSS in Inline CSS.
#googlemap {
height: 600px !important;
}
I have followed below steps.
Step 1: Google API Key must be obtained. Get Google API Key.
Step 2: Create static region with two page hidden items p1_latitude, p1_longitude and region button (Find My Location).
Note: Button action should be "Defined by Dynamic Action".
Step 4: Add custom CSS in Inline CSS.
#googlemap {
height: 600px !important;
}
Note: Normal Page - Height: 600px; | Modal Dialog - Height: 400px;.
That's it. Happy APExing!!!...
Faced Issues: I would like to share all the issues which i faced when i was integrating Oracle APEX with Google Maps.
Step 5: Add below js in Page HTML Header.
<script >
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('googlemap'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 8
});
}
</script>
<script src = "https://maps.googleapis.com/maps/api/js?key=MY_GOOGLE_API_KEY&libraries=places&callback=initMap" async defer>
</script>
Note:
googlemap - Static ID for that particular region or division.
In the end of code, you can find link,
<script src = "https://maps.googleapis.com/maps/api/js?key=MY_GOOGLE_API_KEY&libraries=places&callback=initMap" async defer>
</script>
You must replace MY_GOOGLE_MAP_API_KEY with your valid Google MAP API Key.
Step 6: Create Dynamic Action, it should fire when you click on button "Find My Location".
True Action: Execute JavaScript Code. (Copy and Paste below JS in JS section)
var map = new google.maps.Map(document.getElementById('googlemap'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 15
});
var infoWindow = new google.maps.InfoWindow({
map: map
});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
$('#P1_LATITUDE').val(position.coords.latitude);
$('#P1_LONGITUDE').val(position.coords.longitude);
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesnot support geolocation.');
}
Output: The moment you click on button "Find My Location", you will have a output as like below.
Fig 1: Location Found.
Fig 2: Error Found.
Error Description:
Note that when using the geolocation API and especially when you’re running your page in Google Chrome, the address from which you run your page must be secure (HTTPS). If you’re running local, then no worries as your localhost is considered secure.
If you’re testing on http://apex.oracle.com there are no issues too. If you have problems due to being on HTTP and not HTTPS, try another browser like Mozilla/IE.
Faced Issues: I would like to share all the issues which i faced when i was integrating Oracle APEX with Google Maps.
References:
- https://developers.google.com/maps/documentation/javascript/tutorial
- https://developers.google.com/maps/documentation/javascript/error-messages
- https://developers.google.com/maps/documentation/geocoding/intro
- http://farzadsoltani.com/2017/02/07/implementing-google-maps-oracle-apex/
Related Posts:
- Integrating Oracle APEX with Google Maps | Spot the Location by Providing Multiple Latitude & Longitude
- Integrating Oracle APEX with Google Maps | Spot the Location by Providing Address/Location
- Reverse Geocoding
- Integrating Oracle APEX with Google Maps | Spot the Location & Get the Address by Providing Latitude and Longitude
Comments
Post a Comment