Gopi Nath Gopi Nath - 2 years ago 397
Javascript Question

How to access google maps api in China

I am using google maps api to get user location in my IBM Mobilefirst project and it is working fine as expected in all the countries except china.I know this is because china has blocked access to google apis in their country.Is there any workaround that I can make so that the application works even in china. I have given the code snippet below for reference.

This is the script I have in head

<script type="text/javascript" src=""></script>

javascript code

function getLocation() {
busy = new WL.BusyIndicator ();;
if (navigator.geolocation) {

navigator.geolocation.getCurrentPosition(showPosition, showError,options);
} else {
alert( "Geolocation is not supported");}

function showPosition(pos) {

var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude);
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var addresscomponent=results[0].address_components;
var addresslength=addresscomponent.length;
for(var i=0;i<addresslength;i++){
else if(addresscomponent[i].types[0]=='locality'){

function showError(error) {

Answer Source

Why can't I access Google Maps APIs from China?

The Google Maps APIs are served within China from the domain This domain does not support https. When making requests to the Google Maps APIs from China, please replace with

For example:,+Mountain+View,+CA

would become:,+Mountain+View,+CA

reference :Google FAQ

For country use this:

$.getJSON("", function (data) {
        var country = data.country_name;//your country
<script src=""></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download