How to access google maps api in China

I use google maps api to get the location of a user in my IBM Mobilefirst project, and it works fine, as expected in all countries except china. I know that this is because China has blocked access to google apis in their country. any workaround that I can make the application work even in China. I gave the below code snippet for reference.

This is a script in my head

 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBaKx9iQrPQuOmAc2DkMRgjFdT0_XTdbmE&sensor=false&v=3&libraries=geometry"></script>

javascript code

function getLocation() {
    busy = new WL.BusyIndicator ();
    busy.show();
    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);
    latitude=pos.coords.latitude;
    longitude=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++){
                if(addresscomponent[i].types[0]=='country'){
                    countryname=addresscomponent[i].short_name;
                }
                else if(addresscomponent[i].types[0]=='locality'){
                    cityname=addresscomponent[i].short_name;
                }
            }
}

function showError(error) {
    alert(error);
    busy.hide(); 
       }
+3
source share
3 answers

Why can't I access the Google Maps API from China?

API Google maps.google.cn. https. API Google https://maps.googleapis.com http://maps.google.cn.

:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

:

http://maps.google.cn/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

: Google FAQ


:

$.getJSON("http://ip-api.com/json/", function (data) {
        var country = data.country_name;//your country
        alert(country);
        
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Hide result
+17

?

if((pos.coords.latitude>=37 && pos.coords.latitude<=47)&& (pos.coords.latitude>=110 && pos.coords.latitude<=123))
{

//china
var googleGeocoding="http://maps.google.cn/maps/api/geocode/json?language=en&latlng=" + pos.coords.latitude + "," + pos.coords.longitude + "&key=" + Google_API_Key;
}else {
  
var googleGeocoding="https://maps.googleapis.com/maps/api/geocode/json?language=en&latlng=" + pos.coords.latitude + "," + pos.coords.longitude + "&key=" + Google_API_Key;
}
Hide result

... - ... - 37 ~ 47, 110 ~ 123... http://www.latlong.net

, ... ... http://maps.google.cn/"

, ...

+1

Without API call position or other external services:

<script src="https://maps.googleapis.com/maps/api/js?key=[key]"></script>
<script>
    //Fallback pour google Map api
    window.google || document.write('<script src="http://maps.google.cn/maps/api/js?key=[key]">\x3C/script>');
</script>
0
source

All Articles