【问题标题】:creating google maps api marker using json data and AJAX使用 json 数据和 AJAX 创建谷歌地图 api 标记
【发布时间】:2014-03-17 19:56:58
【问题描述】:

我正在使用 Instagram API,我正在尝试通过将 Instagram 图片中的经度和纬度存储在 JSON 文件中来在 Google 地图上创建标记。

这是我来自 Instagram API 并创建 JSON 文件的代码

<?php
$lat = 51.917367;
$lon = 4.462299;
$client_id = "my-client-id";

$link = 'https://api.instagram.com/v1/media/search?lat=' . $lat . '&lng=' . $lon . '&client_id=' . $client_id . '&distance=200';
$data = file_get_contents($link);

$result = json_decode($data);


$locations = [];

foreach ($result->data as $post):{
    $images = $post->images->thumbnail->url;
    $latitude = $post->location->latitude;
    $longitude = $post->location->longitude;
    $locations [] = ["longitudes"=>$longitude, "latitudes"=>$latitude, "images"=>$images];
} endforeach;

header("Content-Type: application/json");
echo json_encode($locations);
exit;

我的问题是如何使用 AJAX 从 JSON 文件中获取经度和纬度,然后在谷歌地图上的这个位置创建一个标记(使用图像)。

【问题讨论】:

    标签: ajax json api google-maps instagram


    【解决方案1】:

    这是一个向谷歌地图添加标记的代码示例,看起来您已经有代码来获取数组中的位置信息,请使用此代码将其添加到地图:

    https://developers.google.com/maps/documentation/javascript/examples/icon-complex

    【讨论】:

      猜你喜欢
      • 2021-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多