Skip to Content
0

Google maps API with OpenUI5 CORS error

Sep 12, 2017 at 02:03 PM

55

avatar image

Dear Gurus

I was trying to create an app that displays user address based on his coordinates with google maps api the code is working fine inside eclipse ide but when i hos it on IIS i receive the following error

XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/geocode/json?latlng=30.0043704,31.176554&sensor=true&key=AIzaSyCEZN8UB34nbx3D-17xk1J-DRnNCF_kjm4. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

And my code is below

var position = null;
				if (navigator.geolocation) {
					navigator.geolocation.getCurrentPosition(function(aPosition) {
						position = aPosition;
						jQuery.sap.require("sap.m.MessageToast");
						$.sap.log.error("LAT:" + position.coords.latitude + " LON:" + position.coords.longitude);
						var oGeoModel = new sap.ui.model.json.JSONModel();
						var aData = jQuery.ajax({
							type: "GET",
							contentType: "application/json",
							url: "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + position.coords.latitude + "," + position.coords.longitude +
								"&sensor=true&key=AIzaSyCEZN8UB34nbx3D-17xk1J-DRnNCF_kjm4",
							dataType: "json",
							async: false,
							crossDomain: true,
							success: function(data, textStatus, jqXHR) {
								oGeoModel.setData({
									modelData: data
								});
								//alert("success to post");
								myView.byId("txtVendCountry").setValue(oGeoModel.getProperty("/modelData/results/4/formatted_address"));
								myView.byId("txtVendRegion").setValue(oGeoModel.getProperty("/modelData/results/2/formatted_address"));
								myView.byId("txtVendorAddress").setValue(oGeoModel.getProperty("/modelData/results/0/formatted_address"));
								console.log(oGeoModel);
							}
							
						});
						console.log(oGeoModel);
					});
				} else {
					sap.m.MessageToast.show("Sorry, your browser does not support geolocation services.");
				}

Any help would be appreciated

Thanks in advance

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers