简体   繁体   中英

How do I go about adding a place in google maps for china?

I know how to add a place in google maps en, but now my client asked me that he also would want to add a place for google maps china, this is the code that I use for adding a place in en:

        string apiUrl = "https://maps.googleapis.com/maps/api/place/add/json?key=MY_KEY";
        using (HttpClient client = new HttpClient())
        {
            client.BaseAddress = new Uri(apiUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            Google google = new Google
            {
                location = new Coord { lat = branch._Latitude, lng = branch._Longitude },
                name = branch.BranchName,
                phone_number = branch.ContactNO,
                address = branch.Address,
                types = new string[] { "clothing_store" },
                language = "en"
            };

            var myContent = JsonConvert.SerializeObject(google);
            var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.Add("Content-Type", "application/json");
            HttpResponseMessage response = await client.PostAsync(apiUrl, byteContent);

            if (response.IsSuccessStatusCode)
            {
                var data = await response.Content.ReadAsStringAsync();
                GoogleResult googleResult = new GoogleResult(data);
                return googleResult;
            }
        }

I also tried changing the url for the chinese version but it didn't work, I debugged mode and saw that the IsSuccessStatusCode yields to false... For what its worth here is my poor attempt at going about it:

        string apiUrl = "http://maps.google.cn/maps/api/place/add/json?key=MY_KEY";

    // ...

            Google google = new Google
            {
                location = new Coord { lat = branch._Latitude_Chi, lng = branch._Longitude_Chi },
                name = branch.BranchName_Chi,
                phone_number = branch.ContactNO_Chi,
                address = branch.Address_Chi,
                types = new string[] { "clothing_store" },
                language = "zh-CN"
            };

I've also looked everywhere and to no avail I've come here, thanks in advance guys!

Try using the same domain in both calls to the API. Actually you are using maps.googleapis.com and maps.google.cn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM