我知道如何在google maps en中添加一个地方,但现在我的客户问我他也想为google maps china添加一个地方,这是我用来在en中添加地点的代码: / p>
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;
}
}
我也尝试更改中文版的url但是它没有用,我调试模式并看到IsSuccessStatusCode产生错误......这里的价值是我的不良尝试:
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"
};
我也到处寻找并且无济于事我来这里,先谢谢你们!
答案 0 :(得分:0)
尝试在两次API调用中使用相同的域。实际上您使用的是maps.googleapis.com
和maps.google.cn