如何根据用户位置(而不是html5地理定位)将谷歌地图居中?(angularJS)

如何根据用户位置(而不是html5地理定位)将谷歌地图居中?(angularJS),angularjs,html,google-maps,geolocation,Angularjs,Html,Google Maps,Geolocation,我遵循本教程,在本部分的最后一步中,作者展示了一段代码: // Get User's actual coordinates based on HTML5 at window load geolocation.getLocation().then(function(data){ // Set the latitude and longitude equal to the HTML5 coordinates coords = {lat:data.coords.latitude, l

我遵循本教程,在本部分的最后一步中,作者展示了一段代码:

// Get User's actual coordinates based on HTML5 at window load
geolocation.getLocation().then(function(data){

    // Set the latitude and longitude equal to the HTML5 coordinates
    coords = {lat:data.coords.latitude, long:data.coords.longitude};

    // Display coordinates in location textboxes rounded to three decimal points
    $scope.formData.longitude = parseFloat(coords.long).toFixed(3);
    $scope.formData.latitude = parseFloat(coords.lat).toFixed(3);

    // Display message confirming that the coordinates verified.
    $scope.formData.htmlverified = "Yep (Thanks for giving us real data!)";

    gservice.refresh($scope.formData.latitude, $scope.formData.longitude);

});
当我运行他的应用程序(你可以查看)时,浏览器会问我是否同意分享我的位置,如果同意,地图会以我的真实位置为中心并聚焦。但是当我否认的时候,地图显示了美国的中心(我来自欧洲)


所以我的问题是:有没有一种方法可以在用户位置附近将地图居中,以防他拒绝使用真实的GPS数据?例如,基于他的IP地址或主机?在这种情况下,我不需要确切的位置,但如城市或国家将是很好的

如果用户否认在浏览器中的位置,您将无法获得任何信息。没有“一般位置”回退。IP可能是当时任何一种解决方案的唯一选择。我在用户代理中没有看到任何可以提供位置的内容。创建谷歌地图时,可以在实例化时为地图指定默认中心,这在教程中他一定为美国做过

编辑

使用IP,您应该能够找到将IP解析为以下物理区域的服务:

然后,您可以将该位置发送到Google Maps geocoder,以获得一个点,您可以将地图居中,如下所示:


谢谢丹尼尔,是的,他手动将地图居中放置在美国。我知道IP可能是我唯一的选择,所以你能给我一个提示,如何使用这些数据精确地将地图居中?