Hi All,
Do not know if anyone has worked with Google places api or OSplaces api.all similar to Esri javascript api.
I would like to include Google search places api as a function or sources in my search widget code. Don't really know the best way to go about this though.
Google Api search function
https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: -34.397, lng: 150.644}
});
var geocoder = new google.maps.Geocoder();
document.getElementById('submit').addEventListener('click', function() {
geocodeAddress(geocoder, map);
});
}
function geocodeAddress(geocoder, resultsMap) {
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
resultsMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
</script
I want the google search api to carry out the address searches when a user click on a search button to search a post code for example but I want the search result to be displaced on ESri map.
How do I include google api search to the searchWidget sample below
ESRI Search Widget( its also a geocoding service on its own)
Solved! Go to Solution.
Hi All
It just tool complicated to use external service within Esri JavaScript API. I have opted for Esri geocoding service instead it gives me what I need an xy coordinates with addresses.
Thanks...
You should be able to use google's API without pulling anything in from google. It's been a while since I've used a google API but a quick search led me to a couple sample URLs:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEYhttps://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
(source)
You can make requests in these formats using an XHR, or whichever wrapper your prefer (esri/request is an option since you're pulling in the Esri JS API) and get back a list of results, which you can then display how you choose.
I recommend creating your own search widget: you can add a text box, search button, and a place to display results.
The json format you showed is for one entity or location.
I do have a search widget jean Marc Roy helped with this; see link below
====================================================================================================
Searches coming from different featureservers.
var featureSource1 = new FeatureLayer({
url: "https://services7.arcgis.com/uE69mPI6U3rpSmCT/arcgis/rest/services/aAdd_csv/FeatureServer/0",
popupTemplate: { // autocasts as new popupTemplate()
title: "Post Code: ${Postcode}</br>UPRN: ${UPRN}</br>ADDRESS: ${ADDRESS}",
overwriteActions: true
}
})
var featureSource2 = new FeatureLayer({
url: "https://services7.arcgis.com/uE69mPI6U3rpSmCT/arcgis/rest/services/postcodesS/FeatureServer/0",
popupTemplate: { // autocasts as new popupTemplate()
title: "Post Code: ${Postcode_3}</br>Wards Name: ${Ward_Name}</br>Ward: ${Ward_Code}",
overwriteActions: true
}
============================================================================================================
I would like my third source, if possible would like the only source to come from googleApi. I guess when a user types in an address in the search it returns the json format as a lookup and then displaces it on the map.
==================================================================================================================
here is my google map key
Thanks in advance
Hi All
It just tool complicated to use external service within Esri JavaScript API. I have opted for Esri geocoding service instead it gives me what I need an xy coordinates with addresses.
Thanks...